Open EmilienRamos opened 5 years ago
Same, If I change the values bound, the checkboxes won't update (none is selected). Even though the array is updated correctly If I proceed to check another checkbox.
I tried using the compareWith
function and using objects and a simple number[]
too, did not work.
I could trick the component though, by introducing an extra boolean variable showBoundMatSelectionList
, which is true
by default and I added an *ngIf="showBoundMatSelectionList"
for the mat-selection-list
component. This way I can force Angular to destroy the component before I do the patchValue
call using the injected protected ref: ChangeDetectorRef
and reload it afterwards.
this.showBoundMatSelectionList = false;
// now notify angular to check for updates
this.ref.detectChanges();
// do your thing
// patchValues ..etc
this.showBoundMatSelectionList = true;
this.ref.detectChanges();
With this, the mat-selection-list is forced to reload the checkbox values from the supplied array. Does not matter which binding you use.
Check out: https://stackoverflow.com/questions/47496610/destroying-and-reloading-a-child-component
What is the expected behavior?
Checkboxes should update
What is the current behavior?
Checkboxes do not update.
What are the steps to reproduce?
editor.componenet.html
editor.component.ts (onInit)
this.user.attributes.role
is an array of string.I tried editor.component.ts
I also tried editor.component.ts
Note that I'm getting
roles
with an observable : editor.component.tsWhich versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular 7.x.x Material 7.x.x
Is there anything else we should know?
I know there's a ticket about this, but it's closed and no one replies