如何在Angular Material中创建带有md-sidenav的右侧Navbar - Angular 2

时间:2017-03-02 19:41:36

标签: angular angular2-template angular-material2

我正在尝试创建"右侧导航栏"角材料2 md-sidenav。无论我做什么,它总是在左边。我怎样才能改为右侧呢?

  <md-sidenav #sidenavright mode="side" class="app-sidenav" opened="true">
    <app-question-rightnav></app-question-rightnav>
  </md-sidenav>

2 个答案:

答案 0 :(得分:25)

好吧,这比我想象的容易,傻傻的我!!

要将md-sidenav对齐到右侧,只需将align="end"添加到md-sidenav元素。

  <md-sidenav align="end" #sidenavright mode="side" class="app-sidenav" opened="true">
    <app-question-rightnav></app-question-rightnav>
  </md-sidenav>

更新

在更高版本中,它已更改为position="end"

示例

<mat-sidenav #sidenavright position="end">
       Right sideNav
</mat-sidenav>

答案 1 :(得分:6)

<mat-sidenav-container>

    <mat-sidenav #right position="start">
       Start Sidenav.
    </mat-sidenav>

    <mat-sidenav #left position="end">
       End Sidenav.
    </mat-sidenav>

<div>
    <button mat-button (click)="right.open()">right</button>
    <button mat-button (click)="left.open()">left</button>
</div>

</mat-sidenav-container>