background preloader

Angular

Facebook Twitter

Code Organization in Large AngularJS and JavaScript Applications — Cliff Meyers. Many developers struggle with how to organize an application's code base once it grows in size.

Code Organization in Large AngularJS and JavaScript Applications — Cliff Meyers

I've seen this recently in AngularJS and JavaScript applications but historically it's been a problem across all technologies including many Java and Flex apps I've worked on in the past. The general trend is an obsession with organizing things by type. It bears a striking resemblance to the way people organize their clothing. Let's take a look at angular-seed, the official starting point for AngularJS apps. The "app" directory contains the following structure: css/img/js/ app.jscontrollers.jsdirectives.jsfilters.jsservices.jslib/partials/ The JavaScript directory has one file for every type of object we write. This is a mess. The next logical pass at organizing JavaScript involves creating a directory for some of the archetypes and splitting objects into their own files.

Let's imagine we're building a simple e-commerce site with a login flow, product catalog and shopping cart UI's. Nice! AngularJS: 6 Common Pitfalls Using Scopes – TNG - The Nitty Gritty. Within the last month Google's "Superheroic JavaScript MVW Framework" AngularJS has gotten a lot of attention.

AngularJS: 6 Common Pitfalls Using Scopes – TNG - The Nitty Gritty

What makes this framework so successful compared to other JavaScript frameworks as for example EmberJS, is the value it adds to your HTML templates using (declarative) Data Binding. In the following I will describe some best practices when using AngularJS. If you are not familiar with AngularJS yet, please have a look at angularjs.org to get an overview and check out Kahlil's list of AngularJS Resources. Authentication in Single Page Applications with Angular.js - A Modest Proposal. 9/2/2014 update:The GitHub repo now uses UI-router instead of the standard ngRoute routing module.

Authentication in Single Page Applications with Angular.js - A Modest Proposal

This blog post will still illustrate the original technique utilizing ngRoute, while information regarding the UI-router approach can be found in the GitHub repo as well as this blogpost. The example app in the repo has been deployed to Heroku, so now you can test it out live for yourself right here. A separate blogpost discussing the complementing server-side code can be found here. I have been working a lot with Angular.js lately, and love how easy it makes it to create web applications with rich client-side functionality.

It's an extremely useful asset in keeping your own client-side code lean, making it easy to separate business logic and declarative markup for anything view specific. How do I deal with authentication and authorization in single page applications? The server needs to communicate what permissions/role the client has on inital page load. Setting up client-side routing. Why So Curious ? AngularJs – RequireJs seed. Ayant commencé à utiliser AngularJs récemment, je dois dire que je suis largement conquis. Outre la vision sympathique de surcharger le code Html et la facilité d’arriver rapidement à ce qu’on veut, l’organisation en modules réutilisables est très intéressante puisque propre et donc maintenable et surtout testable. Inspiré par certaines vidéos sur egghead.io (que je recommande vivement), j’ai essayé de pousser encore un peu plus loin le concept de modules indépendants en utilisant RequireJs pour gérer le chargement.

Accompagné par un serveur http basé sur express, voici un template d’un mix AngularJs RequireJs et serveur Express avec les tests adaptés sur Testacular. Présentation du template Architecture L’ensemble des sources de l’application ( serveur + client ) est dans le répertoire src . app.js est un simple serveur http basé sur express qui pointe sur le répertoire public, le reste de l’application est coté client. Chargement de l’application Ca tombe bien, on y est !

Directives Services. Everything you need to understand to start with AngularJS. AngularJS and scope.$apply — Jim Hoskins. If you’ve written a non-trivial amount of code in AngularJS, you may have come across the $scope.

AngularJS and scope.$apply — Jim Hoskins

$apply() method. On the surface, it may seem like just a method you call to get your bindings to update. But why does it exist? And when do you need to use it? To really understand when to use $apply, it’s good to know exactly why we need to use it, so let’s dive in! JavaScript is Turn Based The JavaScript code we write doesn’t all run in one go, instead it executes in turns. Instead, whenever there is a task that takes some amount of time, such as an Ajax request, waiting for a click event, or setting a timeout, we set up a callback function and finish our current turn. Let’s look at an example JavaScript file: var button = document.getElementById('clickMe'); function buttonClicked () { alert('the button was clicked'); } button.addEventListener('click', buttonClicked); function timerComplete () { alert('timer complete'); } setTimeout(timerComplete, 2000); How do we update bindings?