我正在将数据从我的类传递给我的模态,如下所示:当我在模态视图中触发ChangeCheck()
函数时,当我回到checkin
类时,MyMap
并没有改变。你知道我怎么可能从中获得价值我的模态。
@Component({
selector: 'page-my-map',
templateUrl: 'my-map.html',
providers:[CommonVariables]
})
export class MyMap {
checkin:boolean=false;
constructor(public commonvar:CommonVariables,public modalCtrl:
ModalController,
public nav:NavController,public alertCtrl:AlertController) {
}
public openBasicModal() {//this functions is triggered once I click the button to open my Modal
let myModal = this.modalCtrl.create(ModalContentPage,{'myParam':this.checkin});
myModal.present();
}
}
@Component({//this is my modal template
templateUrl:'my-modal.html',
})
export class ModalContentPage {//my modal class
checkin:boolean;
constructor(public alertCtrl:AlertController,
public viewCtrl: ViewController,
params: NavParams,
public commonvar:CommonVariables
) {
this.checkin = params.get('myParam');//I am getting this value from MyClass .
}
ChangeCheck ( ) {//I trigger this function.but when I close the my modal, it doesn't change the checkin which inside `MyClass`.
this.checkin = !this.checkin;
}
dismiss() {
this.viewCtrl.dismiss();
}
}
最佳答案
您还缺少参数的public
public params: NavParams
对您的问题:当然,它不会改变,您必须将其发送回去。
将此添加到您的ModalController类
let myModal = this.modalCtrl.create(ModalContentPage,{'myParam':this.checkin});
myModal.onDidDismiss(data => {
console.log(data);
});
myModal.present();
然后将其添加到您的ModalContentPage类中
dismiss() {
let data = { 'checkin': this.checkin };
this.viewCtrl.dismiss(data);
}