使用angular.js加载页面时出现以下错误。
错误:
Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.6/$injector/modulerr?p0=Channabasavashwara&…20at%20d%20(http%3A%2F%2Foditek.in%2FGofast%2Fjs%2Fangularjs.js%3A19%3A463)
我正在解释下面的代码。
loginRoute.js:
var Admin=angular.module('Channabasavashwara',['ngRoute']);
Admin.config(function($routeProvider){
$routeProvider
.when('/dashboard',{
templateUrl: 'dashboardview/dashboard.html',
controller: 'dashboardController'
});
})
loginController.js:
var loginAdmin=angular.module('Channabasavashwara',[]);
loginAdmin.controller('loginController',function($scope,$http,$window){
$scope.user_login=function(){
if($scope.user_name==''){
alert('user name filed should not keep blank');
}else if($scope.user_pass==''){
alert('password filed should not keep blank');
}else{
var userData={'user_name':$scope.user_name,'user_pass':$scope.user_pass};
console.log('user',userData);
$http({
method: 'POST',
url: "php/Login/login.php",
data: userData,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
console.log('response',response);
alert(response.data['msg']);
location.href='dashboard/';
},function errorCallback(response) {
alert(response.data['msg']);
});
}
}
});
如果我从索引页面删除loginRoute.js
链接,则此错误不会发生。但是这里的imy要求是用户在成功登录后转发到另一个(i.e-dashboard
)页面。请帮我解决这个错误。
答案 0 :(得分:1)
您忘记在控制器中添加require dependancy以进行注入。
替换
loginAdmin.controller('loginController',function($scope,$http,$window){
要
loginAdmin.controller('loginController',['$scope','$http','$window',function($scope,$http,$window){
并替换var loginAdmin=angular.module('Channabasavashwara',[]);
到
var loginAdmin=angular.module('Channabasavashwara');