Expand Minimize

Inject built-in AngularJS dependencies before custom ones in filters

Inject built-in AngularJS dependencies before custom ones in filters

CheckId NG1050601
TypeName InjectBuiltInDependenciesBeforeCustomOnesInFilters
Severity CriticalWarning
Type Filter

When inject dependencies into filters, 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 relativeUrl($rootScope, baseUrl) {
    // ...
}

angular.module('app')
    .filter('relativeUrl', ['$rootScope', 'baseUrl', relativeUrl]);


Bad practice
function relativeUrl(baseUrl, $rootScope) {
    // ...
}

angular.module('app')
    .filter('relativeUrl', ['baseUrl', '$rootScope', relativeUrl]);

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.