Posted 04 Feb 2014. Tagged: js and angularjs

I have recently have had the pleasure to work with Angular.js. The first couple of hours were mostly spend trying to wrap my head around an existing code base and an unfamiliar framework. Over the weekend I had a chance to read up on the documentation. I took some notes on best practices:

Modules

Break up your application/features into multiple modules:

Controllers

Do not use Controllers for:

Services

The purpose of the service factory function is to generate the single object, or function, that represents the service to the rest of the application. That object, or function, will then be injected into any component (controller, service, filter or directive) that specifies a dependency on the service.

Dependency Injection

Use the inline DI annotation:

someModule.factory('greeter', ['$window', function(renamed$window) {
    ...
}]);

Directives

Other Notes:

Conventions