Skip to content

"Cannot read property 'selected' of undefined" accessing #mdSelect.selected in template #3750

Closed

Description

Bug caused by #2722

Expected:
This valid template should not cause an error:

  <md-select #foo><md-select>
  <div *ngIf="foo.selected != null">...</div>

Actual:

Error: "Cannot read property 'selected' of undefined" because in Material's source code, _selectionModel is undefined until ngAfterContentInit:

get selected(): MdOption | MdOption[] {
    return this.multiple ? this._selectionModel.selected : this._selectionModel.selected[0];
}

https://github.com/angular/material2/blame/cd55082a488e58a3f4948bba8e5d0a6771a57233/src/lib/select/select.ts#L411

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions