我想在onAuthStateChanged
结算后根据firebase.init
的结果加载视图。
firebase.init({}).then(
function (instance) {
var listener = {
onAuthStateChanged: function(data) {
console.log(data.loggedIn ? "Logged in to firebase" : "Logged out from firebase");
if (data.loggedIn) {
console.log("User info", data.user);
firebase.removeAuthStateListener(listener);
application.start({ moduleName: "views/home/home" });
}
else {
firebase.removeAuthStateListener(listener);
application.start({ moduleName: "views/splash/splash" });
}
},
thisArg: this
};
firebase.addAuthStateListener(listener);
},
function (error) {
console.log("firebase.init error: " + error);
}
);
但是,我收到此错误:Error: A Frame must be used to navigate to a Page.
当我使用此代码时,应用程序启动正常(尽管没有登录内容):
var firebase = require("nativescript-plugin-firebase");
firebase.init({
}).then(
function (instance) {
console.log("firebase.init done");
},
function (error) {
console.log("firebase.init error: " + error);
}
);
application.start({ moduleName: "views/splash/splash" });
我在这里做错了什么?
答案 0 :(得分:0)
var firebase = require("nativescript-plugin-firebase");
var viewToLoad;
firebase.init({
}).then(
function (instance) {
console.log("firebase.init done");
viewToLoad = ... ; // set your view on success
},
function (error) {
console.log("firebase.init error: " + error);
viewToLoad = ... ; // set your view on error
}
);
application.start({ moduleName: viewToLoad });