Expand Minimize

Inject built-in AngularJS dependencies before custom ones in controllers

Inject built-in AngularJS dependencies before custom ones in controllers

CheckId NG1050401
TypeName InjectBuiltInDependenciesBeforeCustomOnesInControllers
Severity CriticalWarning
Type Controller

When inject dependencies into controllers, inject the built-in AngularJS dependencies first, followed by your custom ones. This will make the code easier to read and maintain.

Good practice

function HomeController($scope, dataService) {
    // ...
}

angular.module('app')
    .controller('HomeController', ['$scope', 'dataService', HomeController]);


Bad practice
function HomeController(dataService, $scope) {
    // ...
}

angular.module('app')
    .controller('HomeController', ['dataService', '$scope', HomeController]);

Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.