Angular 如何修复未捕获错误:模板解析错误:';nb侧边栏';不是已知元素:
我是新来的Nebular,还有其他关于Nebular的详细文档吗?Angular 如何修复未捕获错误:模板解析错误:';nb侧边栏';不是已知元素:,angular,bootstrap-4,sidebar,nebular,Angular,Bootstrap 4,Sidebar,Nebular,我是新来的Nebular,还有其他关于Nebular的详细文档吗? 我已尝试在模块中插入组件。 我制作了一个带有边栏模块的边栏组件 应用程序模块 import { BrowserModule } from '@angular/platform-browser';<br> import { NgModule } from '@angular/core'; import { AppRoutingModule } from './app-routing.module'; import {
我已尝试在模块中插入组件。
我制作了一个带有边栏模块的边栏组件 应用程序模块
import { BrowserModule } from '@angular/platform-browser';<br>
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 { SideBarComponent } from './side-bar/side-bar.component';
import { SideBarModule } from './side-bar/side-bar.module';
@NgModule({
declarations: [
AppComponent,
// SideBarComponent
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
NbThemeModule.forRoot({ name: 'cosmic' }),
NbLayoutModule,
SideBarModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
sidebar.comont.ts
import { Component, OnInit } from '@angular/core';
import {MatSidenavModule} from '@angular/material/sidenav';
import { NbSidebarService } from '@nebular/theme';
@Component({
selector: 'app-side-bar',
templateUrl: './side-bar.component.html',
styleUrls: ['./side-bar.component.scss']
})
export class SideBarComponent implements OnInit {
constructor(private sidebarService:NbSidebarService){}
ngOnInit(){
}
toggle() {
this.sidebarService.toggle(true);
return false;
}
}
sidebar.html
<nb-layout>
<nb-layout-header subheader>
<a href="#" (click)="toggle()"><i class="nb-menu"></i></a>
</nb-layout-header>
<nb-sidebar></nb-sidebar>
<nb-layout-column>Layout Content</nb-layout-column>
</nb-layout>
我希望将程序作为侧栏运行。但是如何修复这个错误呢 未捕获错误:模板分析错误:
“nb侧栏”不是已知元素:
1.如果“nb侧边栏”是一个角度组件,则确认它是该模块的一部分。
2.如果“nb侧栏”是一个Web组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到此组件的“@NgModule.schemas”以抑制此消息。(" [错误->] 版面内容 “”:ng:///SideBarModule/SideBarComponent。html@6:2
有人能帮忙吗?尝试导入
侧栏.module.ts中的侧栏模块
,而不是应用程序模块尝试导入侧栏.module.ts中的侧栏模块
,而不是应用程序模块
试试这个
试试这个
您还需要在AppModule和SideBarModule中导入NbSidebarModule
应用程序模块.ts
import {NbSidebarModule} from '@nebular/theme'
@NgModule({
//...
imports: [
//...
SideBarModule,
NbSidebarModule.forRoot() //<== add this
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
import {NbSidebarModule} from '@nebular/theme'
@NgModule({
//..
imports: [
NbSidebarModule //<== add this
]
})
export class SideBarModule { }
从'@nebular/theme'导入{NbSidebarModule}
@NGD模块({
//...
进口:[
//...
侧边栏模块,
NbSidebarModule.forRoot()//您还需要在AppModule和SideBarModule中导入NbSidebarModule
应用程序模块.ts
import {NbSidebarModule} from '@nebular/theme'
@NgModule({
//...
imports: [
//...
SideBarModule,
NbSidebarModule.forRoot() //<== add this
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
import {NbSidebarModule} from '@nebular/theme'
@NgModule({
//..
imports: [
NbSidebarModule //<== add this
]
})
export class SideBarModule { }
从'@nebular/theme'导入{NbSidebarModule}
@NGD模块({
//...
进口:[
//...
侧边栏模块,
NbSidebarModule.forRoot()//请不要对我们大喊大叫。情不自禁…?请不要对我们大喊大叫。情不自禁…?服务不能在其输入提供程序中导入,我已经这样做了服务不能在其输入提供程序中导入,我已经这样做了模块不能在其自己的模块中插入模块不能在其自己的模块中插入,这可能会有帮助…!!!如何我可以调用路由器而不是路由器吗?它没有发生。它也会给出相同的错误“应用程序侧栏”不是一个已知元素:如何修复此问题我不确定您的确切意思。如果您的组件未被识别,您需要从侧栏模块导出它,并将其导入您尝试使用的任何模块中。如果这没有帮助,考虑询问另一个问题,谢谢。这可能会帮助……!我怎么能调用而不是路由器?它也给了同样的错误“app侧栏”不是一个已知的元素:你如何解决这个问题?我不确定你到底是什么意思。如果你的组件没有被识别,你需要从你的代码[SoubBaseMase[/Cudio]中导出它,并导入它。无论你尝试使用哪一个模块,如果没有帮助,请考虑问另一个问题。
import {NbSidebarModule} from '@nebular/theme'
@NgModule({
//...
imports: [
//...
SideBarModule,
NbSidebarModule.forRoot() //<== add this
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
import {NbSidebarModule} from '@nebular/theme'
@NgModule({
//..
imports: [
NbSidebarModule //<== add this
]
})
export class SideBarModule { }