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

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

问题描述

我正在尝试使用 .Net 创建一个示例 Angular 应用程序,只是想了解如何连接其中两个应用程序,但我无法摆脱这个注入器::模块错误.尝试了各种事情,更改依赖项,删除空括号等,但没有任何变化.我创建了 plunker 来保持这个线程的清洁,链接在下面.

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');
    }
]);

感谢您的时间.

推荐答案

$routeParams 应该使用 Provider 进行后期修复,因为您只能在配置阶段使用提供程序.

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

此外,您应该始终只定义一次应用程序,然后使用该模块将其附加,重新创建 angular.module 将刷新旧应用程序 &新副本将被视为该模块.在您服务&您需要将控制器从 angular.module('angularTest',[]) 更改为 angular.module('angularTest')

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')

此外,您错过了在 LogInController

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

最后一件事,您错过了添加 AuthHttpResponseInterceptor.js ,它无法被 angular 应用识别,并且抛出了未定义的 AuthHttpResponseInterceptor 工厂.

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

工作 Plunkr

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

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