AngularJS Dependency Injection

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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.



Got any AngularJS Question?