angularjs – Angular-JS strict-DI不喜欢从$routeProvider注入
发布时间:2020-12-17 17:25:00 所属栏目:安全 来源:网络整理
导读:我在缩小我的Angular代码时遇到了一些问题,所以我开启了ng-strict-di 一个问题似乎存在于我在app.js配置中解析路由上的承诺的方式 .when('/:userId',{ templateUrl: 'views/main.html',controller: 'MyCtrl',resolve : { myDependency : function(Cache,Mode
我在缩小我的Angular代码时遇到了一些问题,所以我开启了ng-strict-di
一个问题似乎存在于我在app.js配置中解析路由上的承诺的方式 .when('/:userId',{ templateUrl: 'views/main.html',controller: 'MyCtrl',resolve : { myDependency : function(Cache,Model,$route){ return Cache.getCached( $route.current.params.userId); } } }) 然后我将这个已解决的承诺注入MyCtrl控制器 angular.module('myApp') .controller('MyCtrl',[ 'myDependency','$scope','$rootScope','$timeout',function (myDependency,$scope,$rootScope,$timeout) { etc... 但是我收到Angular的错误 [Error] Error: [$injector:strictdi] myDependency is not using explicit annotation and cannot be invoked in strict mode 该问题似乎可追溯到app.js中的解析定义,因为我可以在解析中更改’myDependency’的名称,错误消息使用其中的名称而不是myCtrl中的依赖项名称.我明确列出了myCtrl控制器中依赖项的名称.该应用程序工作,但由于此错误的问题,我无法缩小此代码. 解决方法
遵循strict-di来解决问题.希望这个有效!
resolve : { myDependency : ['Cache','Model','$route',function(Cache,$route){ return Cache.getCached( $route.current.params.userId); } ]} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |