Expand Minimize

Don't inject invalid dependencies in directives

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

CheckId NG1010501
TypeName DontInjectInvalidDependenciesInDirectives
Severity CriticalError
Type Directive

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

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

angular
    .module('app')
    .directive('version', function(scope) {
        // ...
    });


When injecting depependencies into directives, 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')
    .directive('version', function($scope) {
        // ...
    });


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


The $scope 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')
    .directive('version', ['$scope', function($scope) {
        // ...
    }]
);

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.