Expand Minimize

Don't inject invalid dependencies in services

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

CheckId NG1010701
TypeName DontInjectInvalidDependenciesInServices
Severity CriticalError
Type Service

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

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

angular
    .module('app')
    .service('dataService', function(http) {
        // ...
    });


When injecting depependencies into services, 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')
    .service('dataService', function($http) {
        // ...
    });


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


The $http 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')
    .service('dataService', ['$http', function($http) {
        // ...
    }]
);

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.