Ich versuche derzeit, eine Benutzeranmeldeseite zu erstellen, auf der die Benutzerinformationen in einer json Datei gespeichert sind. Ich habe meine GET Methode zu der Datei erstellt, aber ich kann nicht umleiten, nachdem der Benutzer sich erfolgreich angemeldet hat. Kannst du mir helfen?AngularJS Benutzeranmeldung in JSON-Datei
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.
Hier ist mein HTML-Code:
<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>
Mein JavaScript-Code:
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';
}
};
}]);
Meine JSON-Datei:
[
{
"email":"[email protected]",
"Password":"password"
},
{
"email":"[email protected]",
"password":"test999"
},
{
"email":"[email protected]",
"password":"xxx"
}
]
Vielleicht möchten Sie schauen ngRoute oder ui.router. – skubski