Current Setup :
Expected Behavior :
Current Behavior :
Additional Note(s) :
Code Sample :
<mat-select placeholder="Multiclassement" [(ngModel)]="classe.multiclassement" multiple>
<mat-option *ngFor="let c of classes | async" [value]="c">{{c.nom}}</mat-option>
</mat-select>
Since we are dealing with objects, the objects in your multiclassesment
array have no reference to the objects in your classes
array, so therefore Angular cannot make the binding. We can solve this by using compareWith
(docs) like so:
<mat-select [compareWith]="compareWithFn" placeholder="Multiclassement"
[(ngModel)]="classe.multiclassement" multiple>
and TS:
compareWithFn(item1, item2) {
return item1 && item2 ? item1.nom === item2.nom : item1 === item2;
}
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With