I have a form with some types of inputs. There is a mistake in validation in the checkbox type. See the stackblitz demo.
First, check the first item. Then check the second one and then uncheck the first one. It shows error message!
Html:
<form name="form" (ngSubmit)="addBookletForm.valid && addBooklet()" #addBookletForm="ngForm" novalidate >
<label *ngFor="let option of levelCheckboxes">
<div *ngIf="( booklet_level.touched || addBookletForm.submitted) && booklet_level.invalid && booklet_level.errors.required">
<div class="saz-alert saz-alert-red saz-alert-small saz-color-red" *ngIf="booklet_level.errors.required">
This is required!
</div>
</div>
<input name="booklet_level" #booklet_level="ngModel" required value="{{option.value}}" [(ngModel)]="option.checked" type="checkbox">
{{option.name}}
</label>
</form>
Typescript:
levelCheckboxes = [
{ name:'one', value:'1', checked:false },
{ name:'two', value:'2', checked:false },
{ name:'three', value:'3', checked:false }
]
modelObject as it's essentially a JS Object which is passed by reference. Hence the behavior.