Im fairly new to working with angular and was wondering if there is a simple way to first check if the checkbox is selected. If it is selected, I want to pass it to the saveOptions
function. If more than one is selected, I would like to pass them all and save them to an array of options. Can someone help me out?
import { Component } from '@angular/core';
import { forEach } from '@angular/router/src/utils/collection';
import { Options } from 'selenium-webdriver/ie';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
options: any = []
saveOptions(x:any[]){
x.forEach(element => {
this.options.push(element);
});
}
}
<ul class="option-row">
<div class="option-group">
<li><input type="checkbox" id="option-1" value="1" required> <label for="option-1">Option 1</label></li>
<li><input type="checkbox" id="option-2" value="2" required> <label for="option-2">Option 2</label></li>
<li><input type="checkbox" id="option-3" value="3" required> <label for="option-3">Option 3</label></li>
</div>
<!--Want to know how to check if the checkbox is selected and pass the selected options to the method-->
<button type="button" (click)="saveOptions();">Submit</button>
</ul>