homepage.module.ts
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
import { CommonModule } from "@angular/common";
import { HomepageComponent } from "./homepage.component";
import { SharedModule } from "../shared/shared.module";
@NgModule({
declarations: [HomepageComponent],
imports: [
CommonModule,
SharedModule
],
exports: [HomepageComponent],
providers: [],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class HomepageModule {}
shared-module.ts
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
import { CommonModule } from "@angular/common";
import { HeaderComponent } from "./header/header.component";
@NgModule({
declarations: [
HeaderComponent,
],
imports: [
CommonModule,
],
exports: [
HeaderComponent,
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class SharedModule {}
homepage.component.html
<app-header (toggleSideBarForMe)="sideBarToggler($event)"></app-header>
app.module.ts
import { HomepageModule } from "./homepage/homepage.module";
@NgModule({
declarations: [AppComponent],
imports: [
HomepageModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
运行业力时,我遇到了错误。 : 失败:模板解析错误: “ app-header”不是已知元素: 1.如果“ app-header”是Angular组件,请验证它是否属于此模块。 2.如果“ app-header”是Web组件,则将“ CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“ @ NgModule.schemas”以禁止显示此消息。 (“ [错误->]
我是否需要在homepage.component.spec文件中添加任何内容?
答案 0 :(得分:0)