简体   繁体   English

角材料侧面

[英]Angular material sidenav

I am following the material.angular.io documentation. 我正在关注material.angular.io文档。
While building a side navbar i am getting the below error " 'mat-nav-list' is not a known element: " 构建侧面导航栏时,出现以下错误“ 'mat-nav-list' is not a known element:

I have imported the following 我已经导入了以下内容

import { MatSidenavModule } from '@angular/material/sidenav';  

I tried other components by importing the APIs and all work fine except the sidenav 我通过导入API尝试了其他组件,除sidenav之外,其他所有组件都工作正常

I really cannot figure out what went wrong. 我真的不知道出了什么问题。 Any suggestions will be great hep. 任何建议将是巨大的帮助。 Thanks in advance. 提前致谢。

Importing it is not enough, you also need to add it to the same module that your component is defined in. 导入它还不够,还需要将其添加到定义组件的模块中。

@NgModule({
  declarations: [
    MyComponent
  ],
  imports: [
    CommonModule,
    MatSidenavModule
  ]
})
export class MyModule { }

I'm pretty sure that you are also not importing MatListModule from @angular/material/list in your app's module (or create a module dedicated for Material components): 我很确定您也不会从@angular/material/list导入应用程序模块中的MatListModule (或创建专用于Material组件的模块):

material.module.ts : material.module.ts

import { NgModule } from '@angular/core';
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatListModule } from '@angular/material/list';

@NgModule({
  exports: [
    MatSidenavModule,
    MatListModule
  ],
  imports: [
    MatSidenavModule,
    MatListModule
  ]
})
export class MaterialModule { }

app.module.ts : app.module.ts

import { NgModule } from '@angular/core';
import { MaterialModule } from './material.module';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    MaterialModule
  ]
})
export class AppModule { }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM