gpt4 book ai didi

Angular 6 Material - 组件不是已知元素

转载 作者:行者123 更新时间:2023-12-04 02:56:36 24 4
gpt4 key购买 nike

我正在尝试在我的 Angular 6 应用程序中安装 Material Design。我使用命令 ng generate @angular/material:nav myNav 添加了导航示意图。当我编译并提供应用程序时,出现错误

Uncaught Error: Template parse errors: 'my-nav' is not a known element: 1. If 'my-nav' is an Angular component, then verify that it is part of this module.

我的 app.modules.ts 代码如下:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { LayoutModule } from '@angular/cdk/layout';
import { MatToolbarModule, MatButtonModule, MatSidenavModule, MatIconModule, MatListModule } from '@angular/material';
import { MyNavComponent } from './my-nav/my-nav.component';

@NgModule({
declarations: [
AppComponent,
MyNavComponent
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
LayoutModule,
MatToolbarModule,
MatButtonModule,
MatSidenavModule,
MatIconModule,
MatListModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

我的app.component.html代码如下:

<my-nav></my-nav>

请告诉我哪里出错了。

最佳答案

因为它是:

@Component({
selector: 'app-my-nav',
templateUrl: './my-nav.component.html',
styleUrls: ['./my-nav.component.css']
})

您的选择器是 app-my-nav , 因此它是 <app-my-nav></app-my-nav> :

selector identifies this directive in a template and triggers instantiation of the directive.

关于Angular 6 Material - 组件不是已知元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52906400/

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