【发布时间】:2016-03-25 13:15:19
【问题描述】:
我使用 Angular js 和 firebase。 对于我的登录表单和注册表单,我有一个控制器“userController”,它调用我的服务 userProvider 中的函数。
我想在我的视图中显示 firebase 错误消息。我的提供商如何向我的控制器发送消息?
我的代码:
userController.js:
$scope.login = function(user){
userProvider.login(user);
}
userProvider.js:
this.login = function(user){
Auth.$authWithPassword({//on connecte l'utilisateur
email: user.email,
password: user.password
}).then(function(authData) {
console.log("Utilisateur connecté:", authData.uid);
$location.path('#/profil');
}).catch(function(error) {
console.error("Echec connexion:", error);
// I want return the error.code for use it in my controller
});
}
login.html:
<form ng-hide="authData" class="form-signin col-md-6" name="loginForm" novalidate >
<h2 class="form-signin-heading">Connexion</h2>
<p style="color:red;" ng-show="userDataError">{{userDataErrorMessage}}</p>
<div class="form-group" ng-class="{ 'has-error' : loginForm.email.$invalid }">
<label for="inputEmail">Email</label>
<input type="email" class="form-control" placeholder="Email address" ng-model="user.email" name="email" ng-required autofocus>
<p class="help-block text-error" ng-show="loginForm.email.$invalid">Cet email n'est pas valide</p>
</div>
<div class="form-group" ng-class="{ 'has-error' : loginForm.password.$invalid }">
<label for="inputPassword">Password</label>
<input type="password" class="form-control" placeholder="Password" ng-model="user.password" ng-minlength="8" name="password" ng-required>
<p class="help-block text-warning" ng-show="loginForm.password.$error.minlength" >Minimum 8 caractères</p>
</div>
<button class="btn btn-lg btn-primary btn-block" ng-disabled="loginForm.$invalid" ng-click="login(user)">Connexion</button>
【问题讨论】:
标签: angularjs firebase angularfire firebase-authentication