Hello,
I would like to check a checkbox from ChecklistPage and have a checkbox at HomePage automatically be checked. I’m currently doing it using Events by doing the publish on ChecklistPage checkbox function and doing the subscribe on Homepage.
ChecklistPage.html
<ion-item>
<ion-label>I Choose Food. </ion-label>
<ion-checkbox (ionChange)="addCheckbox($event)" color="danger""></ion-checkbox>
</ion-item>
ChecklistPage.ts
addCheckbox(event, checkbox : String) {
if ( event.checked ) {
this.checked.push(checkbox);
} else {
let index = this.removeCheckedFromArray(checkbox);
this.checked.splice(index,1);
};
let choice = event.checked;
this.events.publish('User chose:', choice);
console.log('User chose:', choice)
}
HomePage.html
<ion-item>
<ion-label>
Checklist
</ion-label>
<ion-checkbox [checked]="ischecked"></ion-checkbox>
</ion-item>
HomePage.ts
ischecked: boolean;
constructor(public navCtrl: NavController,
public navParams: NavParams
public events: Events) {
this.events.subscribe('User Chose:', (choice) => {
if (choice === 'true') {
this.ischecked = true;
}
});
}