I am trying to create a multiselect dropdown which is bound to a dynamic property that is getting data from JSON script using service. I was able to show the data in the dropdown easily but whenever I put multiple attribute inside the select tag, the dropdown just starts behaving abnormally and I also can't multiselect the data.
I tried using another ng-multiselect-dropdown package but it was also getting quite tricky. I would like to do it with simple HTML checkboxes and using ngModel. I am sending data to POST request so basically I am trying to send multiple values at the backend.
How can I make this work?
<div class="col-sm-4">
<div class="form-group form-float">
<div class="form-line focused">
<select id="teacherSubjects" #teacherSubjects=ngModel multiple="multiple" required class="validate form-control" name="teacherSubjects" [(ngModel)]="teacher.teacherSubjects"
(change)="onSelect($event.target.value)">
<option style="display:none"></option>
<option *ngFor="let x of subjects" [value]="x.code">{{x.name}}</option>
</select>
<label for="teacherSubjects" class="form-label">Subjects</label>
</div>
<div *ngIf="teacherSubjects.invalid && teacherSubjects.untouched">
<span class="label ">Untouched</span>
</div>
<div *ngIf="teacherSubjects.invalid && teacherSubjects.touched">
<div *ngIf="teacherSubjects.errors.required">
<span class="label ">
<span class="text-danger">Subject is required</span>
</span>
</div>
</div>
<div *ngIf="teacherSubjects.valid">
<span class="label ">ok</span>
</div>
</div>
</div>