Angular Injection

Another way to inject services into your AngularJS app is splitting out the injection into a new line. When doing this method, be sure to order your injections in the same order that they are passed into the controller function.

// GOOD
(function() {
angular
.module('app')
.controller('MyTableController', MyTableController);

MyTableController.$inject = [ 'getTable','tablesService','$scope' ];

function MyTableController(getTable, tablesService, $scope) {
console.log("getTable", getTable);
}
})();

// BAD
(function() {
angular
.module('app')
.controller('MyTableController', MyTableController);

MyTableController.$inject = [ 'getTable','$scope','tablesService' ];

function MyTableController(getTable, tablesService, $scope) {
console.log("getTable", getTable);
}
})();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s