目前我正在試圖創建了用戶信息存儲在一個JSON文件中的用戶登錄頁面。我已經爲該文件創建了我的GET方法,但在用戶成功登錄後似乎無法重定向。你能幫我嗎?AngularJS用戶登錄到JSON文件
I know that user login and validation done on the client side is A BAD IDEA but that is how I want to do it, without using a database.
這裏是我的HTML代碼:
<body ng-controller="myCtrl">
<form id="login-form">
<h3>User Login</h3>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<button type="submit" class="btn btn-default" id="login-button" ng-click="LogOn()">Login</button>
</form>
</body>
我的JavaScript代碼:
var app = angular.module('myApp', [ ]);
app.controller("myCtrl",['$scope', '$http', function($scope, $http){
$scope.LogOn = function(){
$http.get('data.json').then(function(data){
$scope.users = data;
});
if (data.email == email) && (data.password = password{
window.location.href = 'www.google.com';
}
};
}]);
我的JSON文件:
[
{
"email":"[email protected]",
"Password":"password"
},
{
"email":"[email protected]",
"password":"test999"
},
{
"email":"[email protected]",
"password":"xxx"
}
]
你可能要考慮ngRoute或ui.router。 – skubski