

Inject built-in AngularJS dependencies before custom ones in directives |
Inject built-in AngularJS dependencies before custom ones in directives
CheckId | NG1050502 |
---|---|
TypeName | InjectBuiltInDependenciesBeforeCustomOnesInDirectives |
Severity | CriticalWarning |
Type | Directive |
When inject dependencies into directives, 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 version($scope, baseUrl) {
// ...
}
angular.module('app')
.directive('version', ['$scope', 'baseUrl', version]);
// ...
}
angular.module('app')
.directive('version', ['$scope', 'baseUrl', version]);
Bad practice
function version(baseUrl, $scope) {
// ...
}
angular.module('app')
.directive('version', ['baseUrl', '$scope', version]);
// ...
}
angular.module('app')
.directive('version', ['baseUrl', '$scope', version]);
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.