簡體   English   中英

角材2 sidenav錯誤:.open不是函數

[英]angular material 2 sidenav error: .open is not a function

插入器中的代碼可以正常工作,但在我的計算機上不起作用。 當我單擊打開側導航按鈕時,我看到錯誤的錯誤“ .open不是函數” 屏幕截圖

//app.component.html
<mat-sidenav-container class="example-container">
    <mat-sidenav #sidenav class="example-sidenav">
      Jolly good!
    </mat-sidenav>

    <div class="example-sidenav-content">
      <button type="button" mat-button (click)="sidenav.open()">
        Open sidenav
      </button>
    </div>

  </mat-sidenav-container>
//app.component.ts
import { Component, ViewEncapsulation } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  encapsulation: ViewEncapsulation.None,
})
export class AppComponent {
  title = 'app';
}

//app.component.css
.example-container {
    width: 500px;
    height: 300px;
    border: 1px solid rgba(0, 0, 0, 0.5);
  }

  .example-sidenav-content {
    display: flex;
    height: 100%;
    align-items: center;
    justify-content: center;
  }

  .example-sidenav {
    padding: 20px;
  }

您需要在MatSidenavModule的imports部分中添加@NgModule

我轉載了您的錯誤。 看到此鏈接: https : MatSidenavModule @NgModule在此, MatSidenavModule中沒有@NgModule

請參考: https : //material.angular.io/components/sidenav/api

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM