I have a set of dynamic checkboxes in an Angular form:
<div class="form-check" *ngFor="let topic of topics">
<input class="form-check-input" (change)="onChange(f)" #f type="checkbox" [value]="topic.name" name="topicgroup">
<label class="form-check-label" style="font-weight: normal">
{{topic.name}}
</label>
</div>
In my edit component, how do I set them as checked?
I have an array that holds all the options, and one which of the options are checked:
Topics: string[] = ['Topic1', 'Topic2', 'Topic3', 'Topic4', 'Topic5'];
selectedTopics: string[] = ['Topic1', 'Topic2'];
How do I reflect that on my html page?
Update: This is my onChange function:
onChange(f) {
if (this.selectedTopics.indexOf(f.value) == -1) {
this.selectedTopics.push(f.value);
} else {
this.selectedTopics.splice(this.selectedTopics.indexOf(f.value), 1);
}