如果 'nb-card' 是一个 Angular 组件,则验证它是该模块的一部分
If 'nb-card' is an Angular component, then verify that it is part of this module
我在设置 nebular 侧边栏时遇到问题,因为我收到错误:
If 'nb-card' is an Angular component, then verify that it is part of this module.
src/app/pages/components/dashboard/dashboard 中的错误。component.html:5:2 - 错误 NG8001:'nb-card' 不是已知元素:
- 如果 'nb-card' 是一个 Angular 组件,则验证它是该模块的一部分。
- 如果 'nb-card' 是 Web 组件,则将 'CUSTOM_ELEMENTS_SCHEMA' 添加到此组件的“@NgModule.schemas”以禁止显示此消息。
功能模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DashboardRoutingModule } from './dashboard-routing.module';
import { NbSidebarModule, NbLayoutModule } from '@nebular/theme';
import {
NbButtonModule,
NbCardModule,
NbProgressBarModule,
NbTabsetModule,
NbUserModule,
NbIconModule,
NbSelectModule,
NbListModule,
NbMenuModule,
} from '@nebular/theme';
@NgModule({
declarations: [],
imports: [
CommonModule,
DashboardRoutingModule,
NbLayoutModule,
NbSidebarModule,
NbButtonModule,
NbCardModule,
NbProgressBarModule,
NbTabsetModule,
NbUserModule,
NbIconModule,
NbSelectModule,
NbListModule,
NbMenuModule,
]
})
export class DashboardModule { }
应用模块:
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 { NbThemeModule, NbLayoutModule } from '@nebular/theme';
import { NbEvaIconsModule } from '@nebular/eva-icons';
import { NbSidebarModule, NbMenuModule} from '@nebular/theme';
import { DashboardComponent } from './pages/components/dashboard/dashboard.component';
@NgModule({
declarations: [
AppComponent,
DashboardComponent
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
NbThemeModule.forRoot({ name: 'default' }),
NbLayoutModule,
NbEvaIconsModule,
NbSidebarModule.forRoot(),
NbMenuModule.forRoot(),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
仪表板组件:
import { Component, OnInit } from '@angular/core';
import { NbMenuItem } from '@nebular/theme';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {
constructor() { }
items: NbMenuItem[] = [
{
title: 'Profile',
expanded: true,
children: [
{
title: 'Change Password',
},
{
title: 'Privacy Policy',
},
{
title: 'Logout',
},
],
},
{
title: 'Shopping Bag',
children: [
{
title: 'First Product',
},
{
title: 'Second Product',
},
{
title: 'Third Product',
},
],
},
{
title: 'Orders',
children: [
{
title: 'First Order',
},
{
title: 'Second Order',
},
{
title: 'Third Order',
},
],
},
];
ngOnInit(): void {
}
}
仪表板组件 html:
<nb-layout>
<nb-layout-header fixed>Company Name </nb-layout-header>
<nb-sidebar>
<nb-card>
<nb-menu [items]="items" autoCollapse="true">
</nb-menu>
</nb-card>
</nb-sidebar>
<nb-layout-column>
Page Content <button nbButton>Hello World</button>
</nb-layout-column>
</nb-layout>
我们将不胜感激。
谢谢
看起来 dashboard.module 应该声明 dashboard.component 因为 NbCardModule 是在那里导入的。
atm 它在 app.module.
中声明
或者将 dashboard.module 导入到 app.module
我在设置 nebular 侧边栏时遇到问题,因为我收到错误:
If 'nb-card' is an Angular component, then verify that it is part of this module.
src/app/pages/components/dashboard/dashboard 中的错误。component.html:5:2 - 错误 NG8001:'nb-card' 不是已知元素:
- 如果 'nb-card' 是一个 Angular 组件,则验证它是该模块的一部分。
- 如果 'nb-card' 是 Web 组件,则将 'CUSTOM_ELEMENTS_SCHEMA' 添加到此组件的“@NgModule.schemas”以禁止显示此消息。
功能模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DashboardRoutingModule } from './dashboard-routing.module';
import { NbSidebarModule, NbLayoutModule } from '@nebular/theme';
import {
NbButtonModule,
NbCardModule,
NbProgressBarModule,
NbTabsetModule,
NbUserModule,
NbIconModule,
NbSelectModule,
NbListModule,
NbMenuModule,
} from '@nebular/theme';
@NgModule({
declarations: [],
imports: [
CommonModule,
DashboardRoutingModule,
NbLayoutModule,
NbSidebarModule,
NbButtonModule,
NbCardModule,
NbProgressBarModule,
NbTabsetModule,
NbUserModule,
NbIconModule,
NbSelectModule,
NbListModule,
NbMenuModule,
]
})
export class DashboardModule { }
应用模块:
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 { NbThemeModule, NbLayoutModule } from '@nebular/theme';
import { NbEvaIconsModule } from '@nebular/eva-icons';
import { NbSidebarModule, NbMenuModule} from '@nebular/theme';
import { DashboardComponent } from './pages/components/dashboard/dashboard.component';
@NgModule({
declarations: [
AppComponent,
DashboardComponent
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
NbThemeModule.forRoot({ name: 'default' }),
NbLayoutModule,
NbEvaIconsModule,
NbSidebarModule.forRoot(),
NbMenuModule.forRoot(),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
仪表板组件:
import { Component, OnInit } from '@angular/core';
import { NbMenuItem } from '@nebular/theme';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {
constructor() { }
items: NbMenuItem[] = [
{
title: 'Profile',
expanded: true,
children: [
{
title: 'Change Password',
},
{
title: 'Privacy Policy',
},
{
title: 'Logout',
},
],
},
{
title: 'Shopping Bag',
children: [
{
title: 'First Product',
},
{
title: 'Second Product',
},
{
title: 'Third Product',
},
],
},
{
title: 'Orders',
children: [
{
title: 'First Order',
},
{
title: 'Second Order',
},
{
title: 'Third Order',
},
],
},
];
ngOnInit(): void {
}
}
仪表板组件 html:
<nb-layout>
<nb-layout-header fixed>Company Name </nb-layout-header>
<nb-sidebar>
<nb-card>
<nb-menu [items]="items" autoCollapse="true">
</nb-menu>
</nb-card>
</nb-sidebar>
<nb-layout-column>
Page Content <button nbButton>Hello World</button>
</nb-layout-column>
</nb-layout>
我们将不胜感激。
谢谢
看起来 dashboard.module 应该声明 dashboard.component 因为 NbCardModule 是在那里导入的。 atm 它在 app.module.
中声明或者将 dashboard.module 导入到 app.module