I am trying to come up with a simple toggle functionality where an array is built based on selections sent via checkboxes in my Angular 2 app. I seem to remember where you can handle toggling by setting one function to be equal to it's opposite, or something like that. These are the two functions I have for adding and removing array elements:
private onItemSelected(item)
{
if (item)
{
this.itemsArray.push(item);
console.log(this.itemsArray);
return this.itemsArray;
}
}
private onItemRemoved(item)
{
if (item)
{
this.itemsArray.splice(item);
console.log(this.itemsArray);
return this.itemsArray;
}
}
And then in my view I'm trying:
<md-checkbox (change)="onItemSelected('A') === onItemRemoved('A')">A</md-checkbox>
But this is not correct in it's current implementation. However, I do remember seeing something like this, though I can't remember the specific syntax. How can I handle this? Or is there a simpler method to handle an array when items are added and removed based on checkbox selections?
Aucun commentaire:
Enregistrer un commentaire