background preloader

AngularJS

Facebook Twitter

How do I "think in AngularJS" if I have a jQuery background. Leveling Up in Angular - HTML5DevConf. In Angular Alicia Liu @aliciatweet Sr Software Engineer, Lift Enjoyment of Angular AngularRULEZ I'm doingit wrong! Services,modules promises,directives,... Module Organization Module By Feature Supports asynchronous loading of modules in the future From Angular Developer Guide Service vs Factory var Mario = function() { this.size = 'small'; }; Mario.prototype.eatMushroom = function() { this.size = 'large'; }; myModule.service('marioService', Mario); // calls new Mario() Provider Asynchronous Events // in some controller $scope. What happens if the data doesn't load? Promises $q var deferred = $q.defer(); svc.getMario = function() { return deferred.promise; }; ... deferred.resolve(data); ... deferred.reject(error); svc.getMario().then( doStuffWithMario, displayError ); Using Promises Chaining $q.all $q.when Interceptors Resolve myModule.controller('CharacterCtrl', function($scope, character) { $scope.character = character; }); Why Write Custom Directives?

Restrict Scope. Angular University Devoxx 2013. AngularJS Tutorial: Learn to Rapidly Build Real-time Web Apps with Firebase. In response to the feedback from our original tutorial, we decided to take the new version of the tutorial in an entirely new direction. Mucking around in backend code doesn't belong in an AngularJS tutorial, and we've found an elegant solution to this problem.

This tutorial will guide you through the process of creating a frontend-only application. Firebase’s firebase.js and angularFire.js libraries offer an entirely new flavor of application: an app built with no backend server or code. The only parts of this application are the AngularJS app, the Firebase data store, and the minimal backend server to deliver the assets to the browser.

Our intention with this tutorial is to provide the AngularJS community with instructions on how to design and build an ultra-modern application. The application you are building will go beyond basic use of AngularJS, and we will attempt to explore as much of the framework as possible. The tutorial is a living thing, a work in progress. App/js/config.js. Egghead.io: Learn AngularJS with Tutorial Videos & Training @eggheadio. 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. 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! Brian Ford. The AngularJS documentation is great for getting started and for looking up specific API calls. However, it doesn't really tell you how to organize and manage your app as it grows to tens or hundreds of thousands of lines of code. I've collected here some of my observations and best practices for how to manage your sprawling application. First we'll take a look at organization, then move on to some tips on improving performance, and conclude with a brief summary on tools, servers, and build processes. While this post will focus on big apps in particular, there's a great video on YouTube from the December 2012 AngularJS meetup on best practices that's also worth checking out. Don't Write a Huge App The best advice about huge apps is not to make them. Organization Probably the biggest question with large apps is where to put all of that code.

Directories This is the typical folder layout that I recommend: Files I would make an exception for closely related directives. Modules Dependencies Models.