I am using angular 5 and in the html file i need to validate a checkbox to make sure user checks atleast one box. I am able to get an error but not in the way I require. Currently with the below code I am getting an error message after every checkbox option, but I require just one message after all the boxes.
<div class="form-group">
<label for="options">Categories:</label>
<label class = "control-label">
<div *ngFor="let category of initialCategories">
<input class = "form-control" type="checkbox"
name="categories" #categories="ngModel" value="
{{category.name}}" [(ngModel)]="category.checked"
required/> {{category.name}}
<div [hidden]="categories.valid || categories.pristine
||!categories.dirty">
Please select at least one option.
</div>
</div>
</label>
</div>
If I put the div to show error outside the ngFor div then it will show not found error since its outside the loop.