我的应用中有4页。 LoginPage,TransistionPage,FirmsPage和ReportsPage。 如果用户已经过身份验证,我的根页面就是TransistionPage,这个页面只负责从休息中获取数据并将其传递给FirmsPage。
我正在尝试使用nav.popToRoot()从ReportsPage返回根页面(假设用户已经过身份验证,根页面是TransistionPage),但是当我这样做时,我只面对白色空白页面。
//报告页面
@Component({
selector: 'page-report',
templateUrl: 'report.html'
})
export class ReportsPage {
sales: any[];
collectings: any[];
summary: any[];
products: any[];
loading: any;
firmId: string;
constructor() {}
goBack(){
this.navCtrl.pop();
}
}
// Transistion页面
@Component({
selector: 'page-transistion-page',
templateUrl: 'transistion-page.html'
})
export class TransistionPage {
firms: any;
loading: any;
constructor(public navCtrl: NavController, private navParams: NavParams, public loadingCtrl: LoadingController, public firmService: FirmService) {
this.getFirms();
}
ionViewDidLoad() {
console.log('Hello TransistionPage Page');
}
getFirms(){
this.presentLoading();
this.firmService.getFirms()
.subscribe(
data => {
this.firms = data.subeler;
//this.loading.dismiss();
this.navCtrl.push(FirmsPage,{param: this.firms},{animate: true, direction: 'back'});
},
error => alert(error),
() => console.log("firmalar çekildi")
);
}
presentLoading() {
this.loading = this.loadingCtrl.create({
content: "Welcome "+window.localStorage.getItem('username')+ " , directing to the firms page",
duration: 1000,
dismissOnPageChange: false
});
this.loading.present();
}
}
//公司页面
@Component({
selector: 'page-firms',
templateUrl: 'firms.html'
})
export class FirmsPage {
langs;
langForm;
loading: any;
username : string;
firms: any;
constructor(public navCtrl: NavController, private navParams: NavParams, public firmService: FirmService, public loadingCtrl: LoadingController, public authService: Auth) {
this.firms = this.navParams.get('param');
this.username = window.localStorage.getItem('username');
this.langForm = new FormGroup({
"langs": new FormControl('')
});
}
ionViewDidLoad() {
console.log('Hello FirmsPage');
}
doSubmit() {
console.log('Submitting form', this.langForm.value.langs);
this.navCtrl.push(ReportsPage, {param:this.langForm.value.langs},{animate: true, direction: 'back'});
}
logout(): void {
this.authService.logout();
this.navCtrl.setRoot(LoginPage);
}
}
通常,请求正在运行。但是,当我认为我不想加载popToRoot页面时,它可以与我执行请求的位置相关联。我是在构造函数中完成的。这就是为什么popToRoot页面无法提出请求的原因。如果这是问题所在。我在哪里可以请求?
答案 0 :(得分:0)
您应该获取应用的实例以使用popToRoot方法
import { Component} from '@angular/core';
import { App } from 'ionic-angular';
@Component({
selector: 'page-login',
templateUrl: 'login.html'
})
export class LoginPage {
navCtrl = this.appCtrl.getRootNav();
constructor( public appCtrl: App ) {
appCtrl.popToRoot();
}