首先我使用的firebase website的方式解釋,然後只用currentauth和waitforauth在您的旅行功能。你將不得不改變它適合你的程序,但我自己使用它,它的工作原理是這樣的。 (對不起,代碼縮進不好)
.run(["$rootScope", "$state", function($rootScope, $state) {
$rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) {
// We can catch the error thrown when the $requireAuth promise is rejected
// and redirect the user back to the home page
if (error === "AUTH_REQUIRED") {
$state.go("login");
}
});
}])
.state('addtrip', {
url: '/addtrip',
templateUrl: 'views/addtrip.html',
controller: 'AddtripCtrl',
resolve: {
"currentAuth": ["firebaseRef", function (firebaseRef) {
// $requireAuth returns a promise so the resolve waits for it to complete
// If the promise is rejected, it will throw a $stateChangeError (see above)
//return firebaseRef.refAuth().$requireAuth();
return firebaseRef.refAuth().$requireSignIn();
}],
"waitForAuth": ["firebaseRef", function (firebaseRef) {
// $requireAuth returns a promise so the resolve waits for it to complete
// If the promise is rejected, it will throw a $stateChangeError (see above)
return firebaseRef.refAuth().$waitForSignIn();
}],
trips : function(currentAuth, waitForAuth, rootRef,$firebaseArray){
return $firebaseArray(rootRef).child(currentAuth.uid).$loaded();
}
}
它不工作回報的承諾。他只解決auth,但是當我添加旅行解決它的失敗。 – user4550050
你能發佈錯誤嗎? – Ved
沒有錯誤,但頁面沒有上傳。 – user4550050