离子Firebase。获取当前用户

时间:2016-08-05 04:30:55

标签: angularjs ionic-framework firebase firebase-authentication

我想获得当前用户并在页面上显示。我关注Firebase文档并使用{{}}而无法正常工作。我是否会错过其他代码或需要使用其他方式?有人可以举个例子。谢谢youuuuuuuuuuuuuuuuuuu

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

1 个答案:

答案 0 :(得分:1)

&#13;
&#13;
add_column :user_devices,:user_id,:integer
add_foreign_key :user_devices, :users, column: :user_id, primary_key: "user_id"
&#13;
&#13;
&#13;

祝你好运......