KingOfHypocrites
KingOfHypocrites

Reputation: 9537

Dependency Injection Strict Mode (ng-strict-di) raises error even when array notation is used

I am trying to implement ng-strict-di in Angular to check my code for minification. Even though I am using array notation, it tells me that I am not explicitly defining my dependencies.

function(sitesService is not using explicit annotation and cannot be invoked in strict mode

Here is my code:

angular.module('app').factory('sitesService', ['$q', '$http', 'globalContextService', '$rootScope', '$log', function ($q, $http, globalContextService, $rootScope, $log) {
    return {
        ...
    };
}]);

To make sure it wasn't an included dependency, I tried this which also doesn't work:

angular.module('app').factory('sitesService', [function () {
    return {

    };
}]);

The error page returned from Angular is below which also shows the same notation I am already using in their second example: https://docs.angularjs.org/error/$injector/strictdi?p0=function(sitesService

Upvotes: 1

Views: 2352

Answers (1)

PSL
PSL

Reputation: 123739

Though the error message

function(sitesService is not using explicit annotation and cannot be invoked in strict mode

may be a bit misleading, it says that wherever you have injected siteService it has not been explicitly annotated. So you would need to look for places where siteService is being injected and not explicitly annotated. If the issue had been with siteService then you would see similar message regarding the dependencies of siteService. Example:

function($q, $http, globalContextService, $rootScope, $log is not using explicit annotation and cannot be invoked in strict mode

Upvotes: 1

Related Questions