Skip to content

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

Closed

Description

@alexsapps

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

Activity

  1. added a commit that references this issue on Mar 25, 2017
    70dbde1
  2. added a commit that references this issue on Mar 29, 2017
    e82457c
  3. added a commit that references this issue on Apr 16, 2017
    ac476e4
  4. angular-automatic-lock-bot commented on Sep 5, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  5. locked and limited conversation to collaborators on Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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