Expand Minimize

Inject built-in AngularJS dependencies before custom ones in services

Inject built-in AngularJS dependencies before custom ones in services

CheckId NG1050702
TypeName InjectBuiltInDependenciesBeforeCustomOnesInServices
Severity CriticalWarning
Type Service

When inject dependencies into services, 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 dataService($q, $http, sharePointUrl) {
    // ...
}

angular.module('app')
    .service('dataService', ['$q', '$http', 'sharePointUrl', dataService]);


Bad practice
function dataService(sharePointUrl, $q, $http) {
    // ...
}

angular.module('app')
    .service('dataService', ['sharePointUrl', '$q', '$http', dataService]);

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.