如何将 nebular 与 angular 一起使用?
How to use nebular with angular?
我正在关注 https://akveo.github.io/nebular/docs/guides/create-nebular-page#create-nebular-page 创建一个 nebular 页面,但它抛出了如下多个错误:
01: 'nb-sidebar' is not a known element:
1. If 'nb-sidebar' is an Angular component, then verify that it is part of this module.
2. If 'nb-sidebar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
4 <nb-sidebar>Sidebar Content</nb-sidebar>
我已经创建了一个模块,当我转到该页面时,它可以很好地处理一些随机文本,但是当我添加 nebular 代码时,它会抛出错误。
组件中使用的代码 html:
<nb-layout>
<nb-layout-header fixed>Company Name</nb-layout-header>
<nb-sidebar>Sidebar Content</nb-sidebar>
<nb-layout-column>
Page Content <button nbButton>Hello World</button>
</nb-layout-column>
</nb-layout>
模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DashboardRoutingModule } from './dashboard-routing.module';
import { NbSidebarModule, NbLayoutModule, NbButtonModule } from '@nebular/theme';
import { NbIconModule } from '@nebular/theme';
@NgModule({
declarations: [],
imports: [
CommonModule,
DashboardRoutingModule,
NbLayoutModule,
NbSidebarModule,
NbButtonModule,
NbIconModule,
]
})
export class DashboardModule { }
组件代码:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
应用模块:
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} 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(),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
您需要将以下内容添加到 AppModule:
imports: [
// ...
NbSidebarModule.forRoot(),
],
并且,正如您已经完成的那样,将 NbSidebarModule
添加到您的功能模块。参见 NbSidebarComponent
我正在关注 https://akveo.github.io/nebular/docs/guides/create-nebular-page#create-nebular-page 创建一个 nebular 页面,但它抛出了如下多个错误:
01: 'nb-sidebar' is not a known element:
1. If 'nb-sidebar' is an Angular component, then verify that it is part of this module.
2. If 'nb-sidebar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
4 <nb-sidebar>Sidebar Content</nb-sidebar>
我已经创建了一个模块,当我转到该页面时,它可以很好地处理一些随机文本,但是当我添加 nebular 代码时,它会抛出错误。
组件中使用的代码 html:
<nb-layout>
<nb-layout-header fixed>Company Name</nb-layout-header>
<nb-sidebar>Sidebar Content</nb-sidebar>
<nb-layout-column>
Page Content <button nbButton>Hello World</button>
</nb-layout-column>
</nb-layout>
模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DashboardRoutingModule } from './dashboard-routing.module';
import { NbSidebarModule, NbLayoutModule, NbButtonModule } from '@nebular/theme';
import { NbIconModule } from '@nebular/theme';
@NgModule({
declarations: [],
imports: [
CommonModule,
DashboardRoutingModule,
NbLayoutModule,
NbSidebarModule,
NbButtonModule,
NbIconModule,
]
})
export class DashboardModule { }
组件代码:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
应用模块:
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} 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(),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
您需要将以下内容添加到 AppModule:
imports: [
// ...
NbSidebarModule.forRoot(),
],
并且,正如您已经完成的那样,将 NbSidebarModule
添加到您的功能模块。参见 NbSidebarComponent