问题
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