I encountered an issue with my component code where the radio button label does not display correctly when I try to edit it. The radio button value also does not get set correctly to the form value and always shows as "No". Despite adding [ngModel] & [value], I am still unable to see the variable properly.
Form: FormGroup;
ngOnInit(): void {
this.createForm();
if (this.isEdit) {
this.editForms();
}
}
private createForm() {
this.Form = this.formBuilder.group({
isRepository: [{ value: '', disabled: false }],
remember: true
});
isPrivateCheck(val: boolean) {
this.isPrivate = val;
if (this.isPrivate) {
this.buttonName = 'Yes';
} else {
this.buttonName = 'No';
}
}
Below is my HTML code:
<form [formGroup]="Form">
<div class="form-group">
<label>Private Repository</label>
<div class="switch">
<input (change)="isPrivateCheck(false)" type="radio" class="switch-input" id="yes" [ngModel]="isRepository" [value]="buttonName" name="isRepository" formControlName="isRepository">
<label for="yes" class="switch-label switch-label-off">No</label>
<input (change)="isPrivateCheck(true)" type="radio" class="switch-input" id="no" [ngModel]="isRepository" [value]="buttonName" name="isRepository>
<label for="no" class="switch-label switch-label-on">Yes</label>
<span class="switch-selection"></span>
</div>
</div>
</form>
After removing the following HTML code:
<label for="no" class="switch-label switch-label-on">Yes</label>
I notice that the label value disappears entirely.