Angular module injection error

北战南征 提交于 2019-12-12 01:28:44

问题


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.


回答1:


$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



来源:https://stackoverflow.com/questions/31034929/angular-module-injection-error

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