[英]Angular use Shared Modules Component in another module
as a structure I have shared folder and inside there is a shared.module.ts.作为一个结构,我有共享文件夹,里面有一个 shared.module.ts。 And also I have modules folder and inside it I have modules and one of them is Dashboard.module.ts.
而且我还有模块文件夹,里面有模块,其中之一是 Dashboard.module.ts。 I wrote one custom sidebar menu inside shared module and I will use it inside my Dashboard module.
我在共享模块中编写了一个自定义侧边栏菜单,我将在我的仪表板模块中使用它。 Here is my shared.module.ts
这是我的 shared.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CommonModule } from '@angular/common';
import { HeaderComponent } from './header/header-component/header-component.component';
import { LoaderComponent } from './components/loader/loader.component';
import { ModalComponent } from './components/modal/modal.component';
import { SidebarMenuComponent } from './components/sidebar-menu/sidebar-menu.component';
import { WidgetComponent } from './components/widget/widget.component';
import { BarChartComponent } from './components/bar-chart/bar-chart.component';
import { SliderComponent } from './components/slider/slider.component';
import { RightBarComponent } from './components/right-bar/right-bar.component';
@NgModule({
declarations: [
HeaderComponent,
LoaderComponent,
ModalComponent,
SidebarMenuComponent,
WidgetComponent,
BarChartComponent,
SliderComponent,
RightBarComponent
],
imports: [
CommonModule,
BrowserModule,
BrowserAnimationsModule
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
exports:[HeaderComponent,LoaderComponent,ModalComponent,SidebarMenuComponent,RightBarComponent]
})
export class SharedModule { }
RightBarComponent component is the component I want to use. RightBarComponent 组件是我要使用的组件。 I both wrote it inside declarations and exports.
我都在声明和导出中写了它。 and in Dashboard module I wrote one component which is Dashboard component inside html I wrote
在仪表板模块中,我写了一个组件,它是我写的 html 中的仪表板组件
<app-right-bar></app-right-bar>
but it gave error below但它在下面给出了错误
Error: src/app/modules/dashboard/pages/dashboard/dashboard.component.html:2:1
- error NG8001: 'app-right-bar' is not a known element:
错误 NG8001:'app-right-bar' 不是已知元素:
- If 'app-right-bar' is an Angular component, then verify that it is part of this module.
如果“app-right-bar”是 Angular 组件,则验证它是否是该模块的一部分。
- If 'app-right-bar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
如果“app-right-bar”是 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”以禁止显示此消息。
this is my dashboard.module.ts这是我的dashboard.module.ts
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DashboardComponent } from './pages/dashboard/dashboard.component';
import { DashboardRoutingModule } from './dashboard-routing.module';
@NgModule({
declarations: [
DashboardComponent
],
imports: [
CommonModule,
DashboardRoutingModule
],
})
export class DashboardModule { }
and this is my right-bar.component.ts这是我的 right-bar.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-right-bar',
templateUrl: './right-bar.component.html',
styleUrls: ['./right-bar.component.scss']
})
export class RightBarComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
Where is my missing?我的失踪在哪里? Thanks in advance.
提前致谢。
Your missing is that u missed to import Shared module to your Dashboard module您缺少的是您错过了将共享模块导入仪表板模块
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DashboardComponent } from './pages/dashboard/dashboard.component';
import { DashboardRoutingModule } from './dashboard-routing.module';
@NgModule({
declarations: [
DashboardComponent
],
imports: [
CommonModule,
SharedModule,
DashboardRoutingModule
],
})
export class DashboardModule { }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.