0

私は以下のような私のクラスからモーダルにデータを渡しています。ChangeCheck()をモーダルビュー内でトリガーすると、MyMapクラスに戻るときにcheckinは変更されません。私はそれが私のモーダルの価値だと思う。ページとモーダルの間のイオン2依存性注入

@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(); 
    } 

} 

答えて

1

あなたもあなたの質問にあなたのparamsのためpublic

public params: NavParams 

行方不明:讲义1コースのそれは変わりませんが、あなたはそれを返送しなければなりません。

その後、私は私をtrue.letさmistake.the実際のコードではfalse、それを入力した

dismiss() { 
    let data = { 'checkin': this.checkin }; 
    this.viewCtrl.dismiss(data); 
    } 
+0

申し訳ありません、あなたのModalContentPageクラスでこれを追加するには、ModalControllerクラスに

let myModal = this.modalCtrl.create(ModalContentPage,{'myParam':this.checkin}); myModal.onDidDismiss(data => { console.log(data); }); myModal.present(); 

これを追加それを修正してください。 –

+0

変更しましたが、まだ同じです。 –

+0

ありがとうございます! :) @LeRoy –