1
如何從標題工具欄組件中調用left sideav?從angular-material2中的工具欄組件中調用sidenav組件
首標toolbar.component.ts
import {Component, ViewChild} from "@angular/core";
@Component({
selector: 'header-toolbar',
templateUrl: './app/header-toolbar/header-toolbar.component.html',
})
export class HeaderToolbarComponent{ }
首標toolbar.component.html
<md-sidenav-layout>
<left-sidenav #s [sidenavFromLeftSideComponent]="s"></left-sidenav>
<md-sidenav-layout>
<md-toolbar color="primary">
<button md-icon-button (click)="s.toggle()">
<i class="material-icons">menu</i>
</button>
<span>Project name</span>
</md-toolbar>
</md-sidenav-layout>
</md-sidenav-layout>
左sidenav.component.ts
import {Component, Input} from "@angular/core";
@Component({
selector: 'left-sidenav',
templateUrl: './app/left-sidenav/left-sidenav.component.html'
})
export class LeftSidenavComponent{
@Input() sidenavFromLeftSideComponent: any;
}
左sidenav.component.html
<md-sidenav #sidenav>
<button md-button (click)="sidenav.close()">Close</button>
</md-sidenav>
感謝。
P.S.我是新角色。