我想找到一種方法來用Angularjs和Firebase創建一個簡單的登錄表單。我目前有一個簡單的註冊表單,它將一個userName添加到我的firebase數據庫中。我需要知道的只是如何在firebase系統中標識userName後獲取接受用戶的登錄頁面,並且如果數據庫中沒有此類userName,可能會發生回調錯誤。這是我的註冊表格:用戶用Angularjs和Firebase登錄
<html ng-app="myApp">
<body ng-controller="userCtrl">
<div class="centerForm">
<form>
<div class="form-group">
<label for="exampleInputUser">Username</label>
<input type="username" ng-model="userName" class="form-control" id="exampleInputUser" placeholder="username">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" ng-model="userPassword" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
<table class="nav" align="center">
<tr>
<td>
<p><button type="submit" class="btn btn-primary" ng-click="saveUser()">Submit</button>
<a href="#" class="btn btn-info" role="button">Sign Up</a></p>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
,這是我的註冊代碼:
<script>
angular.module('myApp', [])
.controller('userCtrl', function($scope) {
$scope.userName ="";
$scope.userPassword="";
$scope.myData = new Firebase("https://myfirebaseapp.firebaseio.com/")
$scope.saveUser = function() {
$scope.myData.push({userName: $scope.userName});
};
});
</script>
我的登錄表單,然後會看起來像:
<html ng-app="myApp">
<body ng-controller="userCtrl">
<div class="centerForm">
<form>
<div class="form-group">
<label for="exampleInputUser1">Username</label>
<input type="username" ng-model="userName" class="form-control" id="exampleInputUser1" placeholder="username">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" ng-model="userPassword" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
<table class="nav" align="center">
<tr>
<td>
<p><button type="submit" class="btn btn-primary" ng-click="loginUser()">Submit</button>
<a href="#" class="btn btn-info" role="button">Sign Up</a></p>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
你的代碼只把用戶名的火力點,它實際上沒有創建一個帳戶,所以你應該在您實際登錄前先修復此問題。 –