Hello everybody.
I don’t know what i’m doing wrong with modals. I open a simple modal instance and present it. To this modal i will pass data which is an array of objects as options . In the modal i will run a ngFor to render this data, each object from data is represented by a checkbox. Clicking on a checkbox will add to the object a field checked which will be either true or false.
Now the problem appears when i dismiss the modal. The original data which was passed by the component from where i opened the modal will be updated too with the checked field .
Can somebody tell me what happens ?
Here is an example:
class MyClass{
constructor(...)
openDialog(){
this.dialog.create(MyModal, { values: this.values }, {});
}
}
class MyModal{
constructor(...){
this.values = this.viewCtrl.data.values
}
cancel(){
this.viewCtrl.dismiss();
}
done(){
//do something and dimiss
this.viewCtrl.dismiss();
}
}
- modal template
<ion-header>
</ion-header>
<ion-content>
<ion-list>
<ion-item *ngFor="let value of values">
<ion-label>
{{ value.name }}
</ion-label>
<ion-checkbox [(ngModel)]="value.checked">
</ion-checkbox>
</ion-item>
</ion-list>
</ion-content>
<ion-footer>
<button (tap)="done()">Done</button>
<button (tap)="cancel()">Cancel</button>
</ion-footer>