Reputation: 687
I'm trying to retrieve toggle state from the server and update the view accordingly here is the HTML for that
<ion-list *ngIf="this.devices.length > 0 " no-padding >
<ion-item *ngFor="let device of this.devices; let i = index">
<ion-label color="light">{{ device.name }} </ion-label>
<ion-toggle (ionChange)="update_state($event,device.ssid)" (ngModel)="device.ssid" color="secondary"></ion-toggle >
</ion-item>
</ion-list>
I know I can bind an ion-toggle
to an object in ts file using ngModel
but i'm not getting the point how that is going to work with toggles being generated dynamically?
Upvotes: 0
Views: 1830
Reputation: 1280
Make the ngModel two-way binding, change (ngModel) to [(ngModel)]
<ion-toggle (ionChange)="update_state($event,device.ssid)" [(ngModel)]="device.ssid" color="secondary"></ion-toggle >
Upvotes: 1