【发布时间】:2017-04-04 15:58:56
【问题描述】:
我有一个简单的程序,我试图通过检查用户名和密码来重定向使用。但是当条件成立时,我不会被重定向,而是会出现错误。有人可以帮我吗?
片段:
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular-route.min.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
Username: <input type="text" ng-model="username"><br>
Password: <input type="password" ng-model="password"><br>
<button ng-click="submit()">LogIn</button>
<script>
//module declaration
var app=angular.module("myApp",['ngRoute']);
//routing declaration
app.config(function($routeProvider, $httpProvider){
$routeProvider
.when('/login',{
templateUrl: 'login.html'
})
.when('/dashboard',{
templateUrl: 'dashboard.html'
})
.otherwise({
templateUrl: 'login.html'
});
});
//controller declaration
app.controller("myCtrl",function($scope, $location){
$scope.submit= function(){
if($scope.username=='admin' && $scope.password=="admin")
{
$location.path('/dashboard');
//alert("Hi");
}
};
});
</script>
</body>
</html>
错误:
在 XAMPP 中运行文件夹
【问题讨论】:
-
使用sn-p在本地运行,运行良好,一定是其他代码导致错误
-
工作正常!
标签: javascript angularjs ngroute angularjs-ng-route