AngularJSDependency Injection


Syntax

  • myApp.controller('MyController', function($scope) { ... }); // non-minified code

  • myApp.controller('MyController', ['$scope', function($scope) { ... }]); //support minification

  • function MyController(){}

    MyController.$inject = ['$scope'];

    myApp.controller('MyController', MyController); //$inject annotation

  • $injector.get('injectable'); //dynamic/runtime injection

Remarks

Providers cannot be injected into run blocks.

Services or Values cannot be injected into config blocks.

Make sure to annotate your injections so your code will not break on minification.