Javascript 未捕获错误:[$injector:modulerr]带有角度JS
我试图验证字段,但它只显示错误。My index.html和js在同一页中。甚至我也尝试过angular-route.min.js和angular.js的不同版本,但我总是得到相同的错误。 AngularJs |基本登录表单Javascript 未捕获错误:[$injector:modulerr]带有角度JS,javascript,jquery,html,angularjs,Javascript,Jquery,Html,Angularjs,我试图验证字段,但它只显示错误。My index.html和js在同一页中。甚至我也尝试过angular-route.min.js和angular.js的不同版本,但我总是得到相同的错误。 AngularJs |基本登录表单 <body ng-app="myApp"> <div ng-view></div> <script> var myApp = angular.module("myApp"
<body ng-app="myApp">
<div ng-view></div>
<script>
var myApp = angular.module("myApp", [ " ngRoute " ]);
myApp.config(function($routeProvider){
$routeProvider
.when('/', {
templateUrl: 'login.html',
})
.when('/dashboard',{
resolve:{
"check": function($location){
if(!rootScope.loggedIn){
$location.path('/');
}
}
},
templateUrl:'dashboard.html'
})
.otherwise({
redirectTo: '/'
});
});
myApp.controller('LoginCtrl',function($scope){
$scope.submit = function(){
if($scope.username =='admin' && $scope.password =='admin'){
$rootScope.uname = $scope.username; //$rootScope
$rootScope.password $scope.password;
$location.path('/dashboard');
}
};
});
</script>
</body>
</html>
var myApp=angular.module(“myApp”、[“ngRoute”]);
myApp.config(函数($routeProvider){
$routeProvider
。当(“/”{
templateUrl:'login.html',
})
.when(“/dashboard”{
决心:{
“检查”:功能($location){
if(!rootScope.loggedIn){
$location.path('/');
}
}
},
templateUrl:'dashboard.html'
})
.否则({
重定向到:'/'
});
});
myApp.controller('LoginCtrl',函数($scope){
$scope.submit=function(){
如果($scope.username=='admin'&&$scope.password=='admin'){
$rootScope.uname=$scope.username;//$rootScope
$rootScope.password$scope.password;
$location.path(“/dashboard”);
}
};
});
您忘记了$rootScope.password上的“=”
<body ng-app="myApp">
<div ng-view></div>
<script>
var myApp = angular.module("myApp", [ " ngRoute " ]);
myApp.config(function($routeProvider){
$routeProvider
.when('/', {
templateUrl: 'login.html',
})
.when('/dashboard',{
resolve:{
"check": function($location){
if(!rootScope.loggedIn){
$location.path('/');
}
}
},
templateUrl:'dashboard.html'
})
.otherwise({
redirectTo: '/'
});
});
myApp.controller('LoginCtrl',function($scope){
$scope.submit = function(){
if($scope.username =='admin' && $scope.password =='admin'){
$rootScope.uname = $scope.username; //$rootScope
$rootScope.password $scope.password;
$location.path('/dashboard');
}
};
});
</script>
</body>
</html>
myApp.controller('LoginCtrl',function($scope){
$scope.submit = function(){
if($scope.username =='admin' && $scope.password =='admin'){
$rootScope.uname = $scope.username; //$rootScope
$rootScope.password = $scope.password; // here
$location.path('/dashboard');
}
};
模块定义中的字符串中不应该有空格<代码>“ngRoute”和
“ngRoute”
不相等,后者不会被识别为ngRoute模块。您添加了哪些js文件?你添加了angularjs和angular-route.js吗?我也尝试了“ngRoute”,但这两个路由都不起作用。即使在删除angular.js文件后,它也不起作用,所以我将其放在代码中。。