是否有可能以某种方式调用调用模态的控制器的方法?
基本上我有HomePage,其中我调用了UserInfoModal。我可以以某种方式从UserInfoModal调用HomePage.changeStatus吗?
父:
@Component({
selector: 'page-home',
templateUrl: 'HomePage .html',
})
export class HomePage {
...
createModal() {
let myModal = this.modalCtrl.create(UserInfoModal, item,
this.supervisor);
myModal.present();
}
changeStatus(item) {
...
}
}
模态:
@Component({
templateUrl: 'UserInfoModal.html',
selector: 'userinfo-modal'
})
export class UserInfoModal{
...
changeParentStatus() {
// call 'changeStatus()' from parent
}
}
答案 0 :(得分:6)
@JeffHuijsmans在评论中是正确的。您可以使用NavParams
将该函数作为参数传递并调用它。
@Component({
selector: 'page-home',
templateUrl: 'HomePage .html',
})
export class HomePage {
...
createModal() {
let myModal = this.modalCtrl.create(UserInfoModal, {item: item,
supervisor: this.supervisor,change:this.changeStatus.bind(this)});
myModal.present();
}
changeStatus(item) {
...
}
}
在模态中,
export class UserInfoModal{
changeStatus:any;
constructor(private navParams:NavParams){
this.changeStatus = this.navParams.get("change");
}
...
changeParentStatus() {
this.changeStatus();
}
}