-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mat-selection-list list-options don't update when formControl for mat-selection-list is updated with setValue #9085
Comments
…ned too early Fixes the selection list options not being marked as selected if the component's value is set before `ngAfterContentInit`. Fixes angular#9085.
Thanks for the report, there's a PR that should fix the issue. Until the fix gets in you should be able to work around it by setting the initial value either inside |
Awesome thanks guys! |
…ned too early (angular#9090) Fixes the selection list options not being marked as selected if the component's value is set before `ngAfterContentInit`. Fixes angular#9085.
…ned too early (angular#9090) Fixes the selection list options not being marked as selected if the component's value is set before `ngAfterContentInit`. Fixes angular#9085.
I seem to be having this same issue for |
Can you post an example @mtholdefer? You can use this as a starting point. Also keep in mind that the objects might not be getting selected, because |
Here you go: https://stackblitz.com/edit/angular-material2-issue-vagkp7?file=app/app.component.html Below the button is the value on the FormControl object. It begins with everything in the list(so everything is selected). When the button is clicked, I update the FormControl object to contain a partial list. After this update are no selected items in the DOM, despite the FormControl value containing 4 elements. |
That's because |
Ahh thank you very much for the solution. |
Guys ! What I have <mat-selection-list formControlName="role">
<mat-list-option checkboxPosition="before" *ngFor="let role of roles" [value]="role.id">{{ role.attributes.name }}</mat-list-option>
</mat-selection-list> editor.ts (onInit) this.form = this.fb.group({
role: [[...this.user.attributes.role], Validators.required],
});
I tried ngAfterContentInit() {
this.form.patchValue({
'role': [...this.user.attributes.role]
});
} I also tried ngAfterContentInit() {
setTimeout(() => {
this.form.patchValue({
'role': [...this.user.attributes.role]
});
console.log(this.form.value.role);
}, 1000);
} Note that I'm getting combineLatest(
// Others observables ...
this.jsonApi.all('roles').pipe(map(document => document.data)),
).subscribe(([firms, langs, roles]) => {
// Others observables ...
this.roles = roles;
}); In fact, no mat-list-option is selected, however, one of them should be selected |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
Using mat-selection-list you can provide a formControl such as
which will load the
myControl.value
with["MY_VALUE", "MY_VALUE2"]
However when using
myControl.setValue(["MY_VALUE", "MY_VALUE2"])
from an input it doesn't cause the checkboxes to be updated!What is the expected behavior?
Checkboxes should update
What is the current behavior?
Checkboxes do not update
What are the steps to reproduce?
https://angular-material2-issue-bvbjdy.stackblitz.io
What is the use-case or motivation for changing an existing behavior?
When using display components it's good to have inputs controlling these, however this blocks us from passing in values from the outside
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Material: 5.x.x
Angular: 5.x.x
The text was updated successfully, but these errors were encountered: