app.component.html
<form #x="ngForm" (ngSubmit)="submit()">
<div class="form-check form-check-inline">
<input [(ngModel)]="details.a" #a="ngModel" type="checkbox" value="1">
<label class="form-check-label" for="inlineCheckbox1">HELLO A</label>
</div>
<div class="form-check form-check-inline">
<input [(ngModel)]="details.b" #b="ngModel" type="checkbox" value="2">
<label class="form-check-label" for="inlineCheckbox1">HELLO B</label>
</div>
<div class="form-check form-check-inline">
<input [(ngModel)]="details.c" #c="ngModel" type="checkbox" value="3">
<label class="form-check-label" for="inlineCheckbox1">HELLO C</label>
</div>
<button [disabled]="!x.valid" >Submit</button>
</form>
App.Component.ts
export class AppComponent implements OnInit {
details:{
a:boolean,
b:boolean,
c:boolean
} = {
a:null,
b:null,
c:null
}
constructor(){
}
submit(){
console.log(this.details) //to get true or false if checked
}
I am attempting to retrieve the checkbox status and values, intending to store the checked values in variables.
SAMPLE:
If checkboxes 1 and 3 are selected: var x = 1 + 3 x = 4