我正在尝试验证字段,但它只显示错误。我的index.html和js在同一页面中。即使我尝试使用angular-route.min.js和angular.js的不同版本,但我总是得到同样的错误。 AngularJs |基本登录表格
<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>
答案 0 :(得分:0)
你忘记&#34; =&#34;在$ rootScope.password上
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');
}
};