First off, all the credit credit and thanks goes to John Lindquist of egghead.io. If you’re interested in AngularJS, visit egghead.io and watch all of the videos (41 total as I’m writing this), they are well worth it for beginners, and people already using it alike.
While watching these videos, I decided to take some basic notes to serve as best-practice reminders. I’d like to share what I’ve gathered, and annotate it with relevant links that go into deeper discussion.
Testing – set up a testing framework right away. The structure of AngularJS apps is modelled around modularity and dependency injection, making it inherently easy to test them. Do NOT skimp out on this. Get started with Jasmine.
The “Dot” – this one has been mentioned countless times. It’s a very simple pattern and very important for any AngularJS beginner. Essentially, it ensures that you access scope data from the intended scope, rather than overriding/shadowing the existing data somewhere up the prototypal inheritance chain. A thorough rundown can be found here.
Passing arguments to scope methods – rather than directly accessing the scope from within your scope functions, it’s best to define the function with a parameter, and pass the data in as an argument. Makes for better testing, and more declarative / descriptive HTML.
Arguments to directive link functions have a fixed signature – Unlike the parameters of Controller constructors, which are provided via dependency injection (become very familliar with this if you aren’t already) , directive functions have a fixed signature. For example, the link function always gets called with the following arguments: function(scope, iElement, iAttrs, controller). In general, if you see a parameter that begins with a $, it’s probably safe to assume that dependency injection is at play.
That’s it (for now).