1
plunker中的代碼工作正常,但它在我的電腦上無法正常工作。當我點擊打開側導航鍵,我看到錯誤消息「開不是一個函數」 screenshot of the error角材2 sidenav錯誤:.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;
}
這個錯誤,如果你沒有給你的'墊子sidenav'元素的名稱也可能出現被引用,如:'#sidenav'。我看到你的例子有這個,但它也很常見。如果在調用open引用該模板變量'sidenav.open()'時出現拼寫錯誤,則設置拼寫以及確保設置變量是獲取此錯誤時需要檢查的兩件事。 –