Dynamically check a checkbox

#1

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;
                }
              });
            }
#2

Wouldn’t you create a service and store the checked results in a service property, or Storage for longer term availability of the checked values?

#3

Is there not a way to do it with Events?