I have been trying to figure out the best way to set a series of ion-checkbox
's using an array that is fed into my app through an API.
Right now, my app receives some data that looks like this:
{
"data": {
"tags": [
55, 46, 193, 1002
]
}
}
I am then using a series of ion-checkbox
's to display whether or not that tag is selected for a certain item, like this:
<ion-item lines="full">
<ion-label position="fixed" class="ion-text-wrap">Blue</ion-label>
<ion-checkbox slot="end" [(ngModel)]="item.tags" [value]="55" [checked]="item.tags.indexOf(55) > 0"></ion-checkbox>
</ion-item>
I am getting an error with the indexOf
function, saying it's not a function.
Is there a better way to try and create a list of items and see if the value is in an array, and then show the checkbox as checked if it is?
question from:
https://stackoverflow.com/questions/65873294/issues-with-setting-ion-checkbox-value-using-arrays-in-angular 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…