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

↘锁芯ラ 提交于 2019-12-24 11:27:50

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/31732156/dependency-injection-strict-mode-ng-strict-di-raises-error-even-when-array-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!