【问题标题】:How to use nebular with angular?如何使用带角度的星云?
【发布时间】:2020-10-08 20:22:46
【问题描述】:

我正在关注https://akveo.github.io/nebular/docs/guides/create-nebular-page#create-nebular-page 创建一个星云页面,但它引发了多个错误,如下所示:

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>

我创建了一个模块,当我进入该页面时,它可以正常处理一些随机文本,但是当我添加星云代码时它会抛出错误。

组件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 { }

【问题讨论】:

  • 声明:[DashboardComponent],
  • AppModule 长什么样子?

标签: angular nebular


【解决方案1】:

您需要将以下内容添加到 AppModule

imports: [
    // ...
    NbSidebarModule.forRoot(),
  ],

并且,正如您已经完成的那样,将NbSidebarModule 添加到您的功能模块中。见NbSidebarComponent

【讨论】:

  • 感谢您的工作。但是现在我对 EvaIcons 遇到了同样的错误:“nb-icon”不是已知元素:1. 如果“nb-icon”是 Angular 组件,则验证它是否是该模块的一部分。我已经编辑了同样的问题。
  • 我会标记它,如果您能提供帮助,我将不胜感激。例如,对于我添加的每个模块,我都会收到此错误,我添加了 nb-card 并且我得到了 'nb-card' is not a known element:。在 nebular 文档中,他们要求在导入中添加 NbCardModule,我这样做了,但错误仍然存​​在,可能是我错过了您可以告诉的内容。
  • 根据文档,看起来只需要将 NbCard 添加到功能模块中。您在哪个模块中添加了 NbCard?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-09
  • 1970-01-01
  • 2019-08-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多