Looking for angularjs Answers? Try Ask4KnowledgeBase
Looking for angularjs Keywords? Try Ask4Keywords

AngularJSDependency Injection


  • 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


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.