Expand Minimize

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

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

CheckId NG1010502
TypeName NumberOfInjectedDependenciesMatchesNumberOfFunctionParametersInDirectives
Severity CriticalError
Type Directive

When injecting dependencies in directives 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 ($rootScope not specified amongst dependencies to inject)

angular
    .module('app')
    .directive('version', ['$scope', function($scope, $rootScope) {
    }]);


Good practice
angular
    .module('app')
    .directive('version', ['$scope', '$rootScope', function($scope, $rootScope) {
    }]);

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.