我想找到一种方法来用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>
你的代码只把用户名的火力点,它实际上没有创建一个帐户,所以你应该在您实际登录前先修复此问题。 –