Expand Minimize

Use explicit dependency injection annotation in filters with strict DI enabled

When bootstrapping application in strict DI mode, use explicit annotation to inject dependencies in filters

CheckId NG1010603
TypeName UseExplicitDependencyInjectionAnnotationWithStrictDiEnabledInFilters
Severity CriticalError
Type Filter

When bootstrapping application in strict DI mode, you have to use explicit annotation to inject dependencies in filters. Without it, your application will break on runtime.

Bad practice (no explicit annotation used for injecting dependencies into a filter used in an application bootstrapped in strict DI mode)

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

angular.bootstrap(document, ['app'], {
    strictDi: true
});


Good practice
angular
    .module('app')
    .filter('relativeUrl', ['$scope', function($scope) {
        // ...
    }]
);

angular.bootstrap(document, ['app'], {
    strictDi: true
});

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.