【问题标题】:Angularfire: How to wait for firebase to load?Angularfire:如何等待firebase加载?
【发布时间】:2016-12-16 11:50:56
【问题描述】:

在我的离子(角度)应用程序中,

  1. 如何等待 firebase 加载?
  2. 我想根据用户是否通过身份验证来更改应用状态。

目前,firebase.auth().currentUser 返回为 null。

$ionicPlatform.ready(function(){
    firebase.auth().currentUser --> null
});

但是

.controller('MyController', function($scope, $ionicPopup, $firebaseAuth) {
    $scope.$on('$ionicView.afterEnter', function(e) {
        firebase.auth().currentUser --> is valid     
    });
});

【问题讨论】:

标签: angularjs ionic-framework firebase angularfire firebase-authentication


【解决方案1】:

您可以简单地使用$loaded 函数,该函数返回一个promise,该promise 在初始服务器数据下载后解决。

var ref = new Firebase("https://<YOUR_FIREBASE_APP>.firebaseio.com/foo");
var obj = new $firebaseObject(ref);
obj.$loaded().then(function() {
    console.log(obj.$value); // "bar"
});

更多信息:https://www.firebase.com/docs/web/libraries/angular/guide/synchronized-objects.html

【讨论】:

    猜你喜欢
    • 2019-01-18
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    • 2021-11-30
    相关资源
    最近更新 更多