Reputation: 747
I have a list of check boxes , I was able to get the selected values but the problem is once I close and open the model again I need the check boxes to be selected with the previous selected values so far I was able to print it near the label of the check box list.Could anyone suggest me how to do this?
getSelect(isChecked, value) {
if (isChecked === true) {
this.ValArray.push(value);
} else {
this.ValArray.splice(this.multiValArray.indexOf(value), 1);
}
}
<ion-card *ngIf="filt.fieldType === 'Select'">
<ion-label padding-left>
{{filt.label}} {{filterCriteria.filter[filt.name]}}
</ion-label>
<ion-item *ngFor="let val of filt.value.Val | slice:0:showMore; let i=index" class="optional-filter-container">
<ion-label>{{val.label}}</ion-label>
<ion-checkbox color="theme-primary" [(ngModel)]="checked[i]" (ngModelChange)="getSelect(checked[i], val.value); filterCriteria.filter[filt.name] = ValArray;"></ion-checkbox>
</ion-item>
<button class="showmore-button" ion-button color="theme-primary" clear text-center *ngIf="showMore < filt.value.Val.length" (click)="showMore = showMore + filt.value.Val.length">
Show more</button>
</ion-card>
Upvotes: 0
Views: 5874
Reputation: 187
Add one more attribute to ion-checkbox i.e.
[checked]="displayValue"
if 'displayValue' is truthy , it will set the checkbox to checked on go.
In your case 'displayValue' will be an array containing true or false values for each iterated checkbox.
Kindly try this once and share your query or feedback
Upvotes: 1