Firebase Ionik. Dapatkan pengguna saat ini

Saya ingin mendapatkan pengguna saat ini dan menampilkannya di halaman. Saya mengikuti dokumen Firebase dan menggunakan {{}} dan tidak berfungsi. Apakah saya melewatkan kode lain atau perlu menggunakan cara lain? Seseorang bisa memberi contoh. Terima kasihuuuuuuuuuuuuuuuuuu

.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>

person Ikram Syakir    schedule 05.08.2016    source sumber


Jawaban (1)


var user = firebase.auth().currentUser;
if (user != null {
  $scope.user = {
    name: user.displayName,
    email: user.email,
    photoURL: user.PhotoURL
  }
}

Semoga beruntung...

person Community    schedule 05.08.2016
comment
OK saya mengerti. Terima kasih. - person Ikram Syakir; 05.08.2016