【问题标题】:Ionic Firebase. Get current user离子火力基地。获取当前用户
【发布时间】: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


    【解决方案1】:

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

    祝你好运……

    【讨论】:

    • 好的,知道了。谢谢。
    猜你喜欢
    • 2018-03-27
    • 2014-07-14
    • 2016-10-16
    • 1970-01-01
    • 2016-09-17
    • 2018-06-25
    • 2017-11-20
    • 1970-01-01
    • 2021-09-11
    相关资源
    最近更新 更多