我來自Ionic 1,我以離子2開始。 當我在承諾後使用this.nav.push(nameOftheOterPage)時出現錯誤,但當我在promise函數authHandler外部使用它時,此函數this.nav.push完全工作:Ionic 2,this.nav.push()未定義
import {Page, NavController} from 'ionic-angular';
import {ItemDetailsPage} from '../item-details/item-details';
@Page({
templateUrl: 'build/pages/login/login.html'
})
export class LoginPage {
static get parameters() {
return [[NavController]];
}
constructor(nav) {
this.nav = nav;
this.firebaseUrl = "https://MYFIREBASE.firebaseio.com";
this.authType = "login";
this.error_username = false;
}
login(form) {
if(form.controls.username.value === null){
this.error_username = true;
}
else{
/* Authenticate User */
var ref = new Firebase(this.firebaseUrl);
ref.authWithPassword({
email : form.controls.username.value,
password : form.controls.password.value
}, this.authHandler);
}
}
authHandler(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log(authData);
this.nav.push(ItemDetailsPage);
}
}
}
你能幫我嗎?
感謝。
什麼是未定義? 'nav'或'push'? – yarons