本文介绍了即使使用数组符号,依赖注入严格模式(ng-strict-di)也会引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Angular中实现ng-strict-di来检查我的代码是否缩小.即使我使用数组符号,它也告诉我我没有显式定义依赖项.

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.

这是我的代码:

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 {

    };
}]);

下面是从Angular返回的错误页面,该页面还显示了我在第二个示例中已经使用的相同符号: https://docs.angularjs.org/error/ $ injector/strictdi?p0 = function(sitesService

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

推荐答案

尽管错误消息

可能会引起误导,它表示无论您在何处注入 siteService ,都未对其进行显式注释.因此,您需要查找注入了 siteService 且未显式标注的位置.如果问题出在 siteService 上,那么您会看到有关 siteService 依赖项的类似消息.示例:

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:

这篇关于即使使用数组符号,依赖注入严格模式(ng-strict-di)也会引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 10:20