Components: Sidenav is not working under ngIf control.

Created on 8 Dec 2016  路  2Comments  路  Source: angular/components

If the md-sidenav is under ngIf control, I'm getting "Cannot read property 'open' of undefined" when I want to open the sidenav.

Plunker: http://plnkr.co/edit/yEUe7pUZrbhZgfRTHclx?p=preview

P2

Most helpful comment

This is a limitation of ngIf (see https://github.com/angular/angular/issues/6179)

You can work around it by using @ViewChildren:

@ViewChildren('start') sc: QueryList<MdSidenav>;
<md-sidenav-container>
  <md-sidenav #start *ngIf="true">Hi</md-sidenav>
  <button md-button (click)="sc.first.open()">open</button>
</md-sidenav-container>

All 2 comments

This is a limitation of ngIf (see https://github.com/angular/angular/issues/6179)

You can work around it by using @ViewChildren:

@ViewChildren('start') sc: QueryList<MdSidenav>;
<md-sidenav-container>
  <md-sidenav #start *ngIf="true">Hi</md-sidenav>
  <button md-button (click)="sc.first.open()">open</button>
</md-sidenav-container>

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

crutchcorn picture crutchcorn  路  3Comments

michaelb-01 picture michaelb-01  路  3Comments

Miiekeee picture Miiekeee  路  3Comments

MurhafSousli picture MurhafSousli  路  3Comments

LoganDupont picture LoganDupont  路  3Comments