Expand Minimize

Use explicit dependency injection annotation in controllers with strict DI enabled

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

CheckId NG1010404
TypeName UseExplicitDependencyInjectionAnnotationWithStrictDiEnabledInControllers
Severity CriticalError
Type Controller

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

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

angular
    .module('app')
    .controller('HomeController', function($scope) {
        $(".search-details-form").hide();
    }
);

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


Good practice
angular
    .module('app')
    .controller('HomeController', ['$scope', function($scope) {
        $(".search-details-form").hide();
    }]
);

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.