gpt4 book ai didi

html - 我应该如何在 app.module.ts 中导入 MatDrawer 和 MatDrawerContainer? Angular 9

转载 作者:行者123 更新时间:2023-12-04 16:40:05 25 4
gpt4 key购买 nike

当我单击工具栏图标时,我试图使用 Angular Material 打开侧面导航。一切正常,直到我尝试实际打开导航栏,我收到错误:

Unexpected directive 'MatDrawer in @angular/material/sidenav/index.d.ts' imported by the module 'AppModule in /src/app/app.module.ts'. Please add a @NgModule annotation.


这是 npm 模块 (package.json):
"@angular/animations": "^9.1.11",
"@angular/cdk": "^9.2.4",
"@angular/common": "~9.1.11",
"@angular/compiler": "~9.1.11",
"@angular/core": "~9.1.11",
"@angular/forms": "~9.1.11",
"@angular/material": "^9.2.4",
"@angular/platform-browser": "~9.1.11",
"@angular/platform-browser-dynamic": "~9.1.11",
"@angular/router": "~9.1.11",
"jQuery": "^1.7.4",
"jquery": "^3.5.1",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
这是我的 app.module:
import { MatDrawer } from '@angular/material/sidenav';
import { MatDrawerContainer } from '@angular/material/sidenav';

@NgModule({
declarations: [
AppComponent,
DressesComponent,
LoadingSpinnerComponent,
Toolbar,
ButtonToggle,
Sidenav
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
BrowserAnimationsModule,
MatTableModule,
MatSelectModule,
MatDialogModule,
MatInputModule,
MatToolbarModule,
MatIconModule,
MatButtonToggleModule,
MatDrawer,
MatDrawerContainer

],
providers: [DressesService, SidenavService],
bootstrap: [AppComponent]
})
export class AppModule { }
和 app.component.html:
<html dir="rtl" lang="he">
<toolbar></toolbar>
<side-nav></side-nav>
</html>

最佳答案

要导入组件和指令等,您需要导入它们的模块,而不是实际的组件和指令。所以你需要导入MatSidenavModule而不是 MatDrawer , MatDrawerContainer :

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

@NgModule({
declarations: [
AppComponent,
DressesComponent,
LoadingSpinnerComponent,
Toolbar,
ButtonToggle,
Sidenav
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
BrowserAnimationsModule,
MatTableModule,
MatSelectModule,
MatDialogModule,
MatInputModule,
MatToolbarModule,
MatIconModule,
MatButtonToggleModule,
MatSidenavModule //<-- this one

],
providers: [DressesService, SidenavService],
bootstrap: [AppComponent]
})
export class AppModule { }

关于html - 我应该如何在 app.module.ts 中导入 MatDrawer 和 MatDrawerContainer? Angular 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62739012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com