我有一个功能模块noi-dung.module.ts
import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { NoiDungListComponent } from "./noi-dung-list/noi-dung-list.component";
import { NoiDungService } from "./shared/noidung.service";
import { NoiDungRoutingModule } from "./noi-dung.routing";
@NgModule({
imports: [CommonModule, NoiDungRoutingModule],
declarations: [NoiDungListComponent],
providers: [NoiDungService]
})
export class NoiDungModule {
}
我将它导入我的AppModule
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app.routing';
//feature module
import { NoiDungModule } from './noi-dung/noi-dung.module';
@NgModule({
imports: [
BrowserModule,
HttpModule,
NoiDungModule,
FormsModule,
AppRoutingModule,
],
declarations: [
AppComponent,
],
providers: [
],
bootstrap: [AppComponent]
})
export class AppModule { }
我收到此错误
"Template parse errors:
'my-app' is not a known element:
1. If 'my-app' is an Angular component, then verify that it is part of this module.
2. If 'my-app' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("
<body>
[ERROR ->]<my-app>Loading...</my-app>
</body>
"): NoiDungListComponent@27:4"
它告诉我my-app
选择器不在NoiDungListComponent
中
但我不是导出noi-dung.module.ts
my-app
选择器位于AppComponent
import {Component} from '@angular/core';
@Component({
selector:'my-app',
templateUrl: './app/app.html'
})
export class AppComponent {
title = 'App Angular 2 Base';
}
AppComponent
是一个引导程序并在主模块中声明
那么为什么它加载了NoiDungComponent
里面的noi-dung module
并且没有导出到外部而不是声明和引导的组件?
[编辑]在评论中提出答案
答案 0 :(得分:1)
<body>
<my-app>Loading...</my-app>
</body>
应仅在index.html
中,而不在组件模板中。