I have the following 4 checkboxes, generated dynamically. In the angular component, I would like to retrieve the "name", "value" and "state" of the checkbox.
HTML:
<input type="checkbox"
name="automotive"
value="car"
ngModel
(ngModelChange)="filterResults(obj, $event)">
<input type="checkbox"
name="automotive"
value="truck"
ngModel
(ngModelChange)="filterResults(obj, $event)">
<input type="checkbox"
name="apparel"
value="shirts"
ngModel
(ngModelChange)="filterResults(obj, $event)">
<input type="checkbox"
name="apparel"
value="pants"
ngModel
(ngModelChange)="filterResults(obj, $event)">
Component:
filterResults(obj: any, isChecked: boolean){
console.log(obj);
console.log(isChecked); // {}, true || false
}
I am able to get the state of the checkbox, but not the name and value. Upon printing to the console, obj is undefined. I would like to apply filters to a dataset based on the name and value of the checkbox.
How do I get the name and value of the checked checkboxes, so I can do that?