Expand Minimize

Don't inject invalid dependencies in filters

When injecting dependencies in filters ensure that they point to valid objects

CheckId NG1010601
TypeName DontInjectInvalidDependenciesInFilters
Severity CriticalError
Type Filter

When injecting dependencies in filters ensure, that they point to valid objects.

Bad practice (rootScope misses the $-sign at the beginning)

angular
    .module('app')
    .filter('relativeUrl', function(rootScope) {
        // ...
    });


When injecting depependencies into filters, also keep in mind that unless you use the inline array notation, your code might break after minification.

The following code snippet:
angular
    .module('app')
    .filter('relativeUrl', function($rootScope) {
        // ...
    });


After minification could become:
angular.module("app").filter("relativeUrl",function(e){/* ... */});


The $rootScope parameter has been replaced with e which will cause AngularJS to fail finding the matching dependency to inject. To avoid this issue you should inject dependencies using the inline array notation:

angular
    .module('app')
    .filter('relativeUrl', ['$rootScope', function($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.