角模块误注入 [英] Angular module injection error

查看:174
本文介绍了角模块误注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建与.net样本角应用程序,只是为了让这个想法如何连接其中的两个,但我无法摆脱这种注射器:: modulerr的错误。尝试过各种各样的事,改变依赖,消除空方括号等,但没有改变。我创建plunker保持这种清纱器的链接如下。

http://plnkr.co/edit/5AHsUSrFib4dkiX6XjLY?p=$p$ PVIEW

我觉得错误不断从这一个未来

\r
\r

angular.module('angularTest',['ngRoute'])。配置( ['$ routeProvider','$ routeParams','$ httpProvider',\r
    功能($ routeProvider,$ routeParams,$ httpProvider){\r
        的console.log('1');\r
        $ routeProvider。\r
            当('/ RouteOne公司',{\r
                templateUrl:routesDemo /一个人\r
            })\r
            。当('/ routeTwo /:甜甜圈',{\r
                templateUrl:功能(PARAMS){return'指令/ routesDemo /双甜甜圈='+ params.donuts}\r
            })\r
            。当('/ routeThree',{\r
                templateUrl:routesDemo /三化\r
            })\r
            。当('/登录?RETURNURL',{\r
                templateUrl:'/帐号/登录',\r
                控制器:的LoginController\r
            });\r
        的console.log('2');\r
        $ httpProvider.interceptors.push('AuthHtt presponseInterceptor');\r
    }\r
]);

\r

\r
\r

感谢您的时间。


解决方案

$ routeParams 应该是后修复与提供你只能使用提供商的配置阶段。

此外,你应该始终定义的应用程序只有一次,然后通过该模块,再造 angular.module 将刷新旧的应用程序和放追加它;新副本将视为该模块。在您服务与;控制器,你需要从 angular.module变化('angularTest',[]) angular.module('angularTest')

此外你错过添加 的LoginController

 。当('/登录?RETURNURL',{
     templateUrl:'/帐号/登录',
     控制器:'LoginController中'//< - 在这里添加qoutes
  });

最后一件事,你错过了加入 AuthHtt presponseInterceptor.js 这是不是由角应用识别和被扔 AuthHtt presponseInterceptor 工厂没有定义。

工作Plunkr

I am trying to create a sample Angular app with .Net, just to get the idea how to connect two of them but I can not get rid of this injector::modulerr error. Tried variety of things, changing dependencies, removing empty brackets and so on but nothing changes. I have created plunker to keep this thread cleaner the link is below.

http://plnkr.co/edit/5AHsUSrFib4dkiX6XjLY?p=preview

I think the error keeps coming from this one

angular.module('angularTest', ['ngRoute']).config(['$routeProvider', '$routeParams', '$httpProvider',
    function ($routeProvider, $routeParams, $httpProvider) {
        console.log('1');
        $routeProvider.
            when('/routeOne', {
                templateUrl: 'routesDemo/one'
            })
            .when('/routeTwo/:donuts', {
                templateUrl: function (params) { return '/routesDemo/two?donuts=' + params.donuts }
            })
            .when('/routeThree', {
                templateUrl: 'routesDemo/three'
            })
            .when('/login?returnUrl', {
                templateUrl: '/Account/Login',
                controller: LoginController
            });
        console.log('2');
        $httpProvider.interceptors.push('AuthHttpResponseInterceptor');
    }
]);

Thanks for your time.

解决方案

$routeParams should be post fix with Provider as you can only use provider in config phase.

Also you should always define app only once then append it by using that module, recreating angular.module will flush the old app & new copy will treated as that module. In you service & controller you need to make change from angular.module('angularTest',[]) to angular.module('angularTest')

Additionally you missed to add ' on LogInController

  .when('/login?returnUrl', {
     templateUrl: '/Account/Login',
     controller: 'LoginController' //<--here added qoutes
  });

One last thing, you missed to add AuthHttpResponseInterceptor.js which was not recognize by the angular app and was throwing AuthHttpResponseInterceptor factory not defined.

Working Plunkr

这篇关于角模块误注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆