lundi 8 avril 2019

Get values from a group of Angular Material checkboxes?

I'm trying to figure out how to get the selected values of a group of Angular (7) Material checkboxes.

Let's say I have an area on the form "flavors" and 3 checkboxes with values of "chocolate", "vanilla", and "strawberry".

<h3>Flavors</h3>
<mat-checkbox value="chocolate">Chocolate</mat-checkbox>
<mat-checkbox value="vanilla">Vanilla</mat-checkbox>
<mat-checkbox value="strawberry">Strawberry</mat-checkbox>

As the checkboxes are checked on and off, I want to update the variable (model) "flavorsAvailable".

It's simple to do this with mat-radio-groups, since it's just an ngModel on the group element. But how do I manage checkboxes?

Note: I don't want to use an Angular Material Selection list; this is just for forms.




Aucun commentaire:

Enregistrer un commentaire