Skip to content

AngularJS Best Practice

Vi edited this page Jun 10, 2014 · 1 revision

AngularJS Best Practice

Explicit Dependency Inject

A component should explicitly define its dependencies using one of the injection annotation methods:

  1. Inline array injection annotation (preferred):

    myModule.controller('MyController', ['$location', function($location) { ... }]);
    
  2. $inject property:

    var MyController = function($location) { ... };
    MyController.$inject = ['$location'];
    myModule.controller('MyController', MyController);
    

See: Explicit Dependency Inject

Clone this wiki locally