【发布时间】:2016-12-11 09:25:03
【问题描述】:
我想获取当前用户并在页面上显示。我关注 Firebase 文档并使用 {{}} 并且无法正常工作。我是否错过了其他代码或需要使用其他方式?有人可以举个例子。谢谢你uuuuuuuuuuuuuuuuuu
.controller('dashCtrl', function($scope, $state, $ionicPopup, $ionicLoading, $firebaseAuth) { //library injection
var user = firebase.auth().currentUser; // code from firebase docs
var name, email, photoUrl, uid; //declare the variable
//checking the user
if (user != null) {
name = user.displayName; //fetch the name
email = user.email; // fetch the email
photoUrl = user.photoURL; // fetch
uid = user.uid; // fetch uid
//password = user.password;
// The user's ID, unique to the Firebase project. Do NOT use
// this value to authenticate with your backend server, if
// you have one. Use User.getToken() instead.
console.log(email); //log the email. success display at console
console.log(uid);
}
//logout function
$scope.logout=function(){
firebase.auth().signOut().then(function() {
console.log("Sign-out successful.");
$state.go('login');
}, function(error) {
// An error happened.
});
}
})
<ion-view hide-back-button="true" cache-view="false" ng-controller="dashCtrl">
<ion-nav-title>Dashboard</ion-nav-title>
<ion-nav-buttons side="right">
<button class="button icon ion-log-out" ng-click="logout()"></button>
</ion-nav-buttons>
<ion-content class="padding has-header" scroll="true">
// need to display at this title
<br>
<center><h4><font color="#FFFFFF">Welcome to your dashboard, {{user.email}}</font></h4></center>
<br>
<button class="button button-block button-calm">
<h7>Update Email</h7>
</button>
</ion-content>
</ion-view>
【问题讨论】:
标签: angularjs ionic-framework firebase firebase-authentication