【发布时间】:2017-05-02 09:07:41
【问题描述】:
我确信这是一个简单的问题,但由于我在 Angular 中工作了大约 2 周,现在我似乎无法弄清楚。
我有这个带有 firebase 功能的 facebook 登录:
function FBLogin(){
var provider = new firebase.auth.FacebookAuthProvider();
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Facebook Access Token. You can use it to access
the Facebook API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
console.log(user.displayName);
$scope.user = user.displayName;
$scope.loggedIn = true;
// ...
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
console.log(error);
// ...
});
}
$scope.user 应该在返回承诺时向我显示 HTML 中的用户名,对吗?它不会那样做。
HTML:
函数调用按钮:
<a ui-sref=".dashboard" class="btn btn-primary">
<img class="logo-image" src='components/images/login-button-png-
18039.png' width="140" height="50" ng-click="vm.FBLogin()" ng-
if="!loggedIn">
</a>
应该显示数据的字段:
<p ng-if="loggedIn">{{ user }} xxx</p>
用户名显示在控制台中,但不在 HTML 中。
【问题讨论】:
-
firebase是 Angular 服务吗?如果不是,则需要使用$scope.apply()通知 Angular 范围更改。 -
好吧,我以为很简单,谢谢 :D
标签: angularjs firebase angular-promise