-
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
fix(material/chips): error if selected value is accessed too early #23419
Conversation
src/material/chips/chip-list.ts
Outdated
@@ -154,7 +154,7 @@ export class MatChipList extends _MatChipListBase implements MatFormFieldControl | |||
|
|||
/** The array of selected chips inside chip list. */ | |||
get selected(): MatChip[] | MatChip { | |||
return this.multiple ? this._selectionModel.selected : this._selectionModel.selected[0]; | |||
return this.multiple ? this._selectionModel?.selected : this._selectionModel?.selected[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MatChip[] | MatChip
type here seems off, since this can return undefined. I don't think we can fix it without a breaking change, but in the multiple case we could at least return an empty array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed, although my thinking is that this is somewhat of an edge case. You'll have to try access selected
before change detection has run in order for it to break (e.g. by doing it in the constructor). I submitted the fix since we had a similar issue report in mat-select
.
Similar issue to angular#23378. The chip list will throw an error if the `selected` value is accessed before the selection model has been initialized.
fde293e
to
d8467af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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. |
Similar issue to #23378. The chip list will throw an error if the
selected
value is accessed before the selection model has been initialized.