Expand Minimize

Number of injected dependencies matches the number of function parameters in services

When injecting dependencies in services ensure that they match the function parameters

CheckId NG1010702
TypeName NumberOfInjectedDependenciesMatchesNumberOfFunctionParametersInServices
Severity CriticalError
Type Service

When injecting dependencies in services ensure that the specified dependencies match the function parameters. Any additional parameters specified in the function, will be omitted and AngularJS won't assign any dependencies to them.

Bad practice ($q not specified amongst dependencies to inject)

angular
    .module('app')
    .directive('dataService', ['$http', function($http, $q) {
    }]);


Good practice
angular
    .module('app')
    .directive('dataService', ['$http', '$q', function($http, $q) {
    }]);

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.