When key1 checkbox is checked, I want to check and disable key2 checkbox
HTMLcode
<input class="form-check-input" type="checkbox" formControlName="key1" id="key1" (click)="key1Click()">
<label for="key1" class="form-check-label">Key 1</label>
<input class="form-check-input" formControlName="key2" type="checkbox" id="key2">
<label for="key2" class="form-check-label">Key 2</label>
Typescript code for checkbox
keyClick() {
let x = <HTMLInputElement>document.getElementById("key1");
let y = <HTMLInputElement>document.getElementById("key2");
if (x.checked) {
y.checked = true;
y.disabled = true;
}
else {
y.checked = false;
y.disabled = false;
}
}
By using this code key2 checkbox is checked and disabled. But the boolean value of key2 checkbox remains false. Any suggestions on how can I change the boolean value of key2 checkbox to true when I click key1 checkbox I am using Angular 8 and its reactive forms module.I am new to angular.