<form (submit)="onSubmit()">
<div class="container">
<div *ngFor="let initial of initialState,let j = index" >
<div *ngIf="initial>0">
<button class="button" type="button">Device </button>
<label class="switch">
<input type="checkbox" id="checkbox_category" checked (change)="search(initial, $event)" />
<div class="slider round"></div>
</label>
<br/>
</div>
<div *ngIf="initial===0">
<button class="button" type="button">Device </button>
<label class="switch">
<input type="checkbox" id="checkbox_category" (change)="search(initial, $event)" />
<div class="slider round"></div>
</label>
<br/>
</div>
</div>
</div>
<button class="button" type="button">Submit</button>
</form>`enter code here`
export class DashboardComponent{
initialState:any = [1,1,1,0,0,0,1];
intendedDeviceStatus: any = this.initialState;
search(category:any, event:any) {
var index = this.initialState.indexOf(category);
this.intendedDeviceStatus[index]= (~this.intendedDeviceStatus[index]);
}
In the above code i have a Initailstatus array which gives me which checkboxes are checked and unchecked ....based on that after displaying checkboxes.After Displaying it when i change checked checkbox to uncheck it not getting updated in IntendedDevicesArray.
Aucun commentaire:
Enregistrer un commentaire