2017-02-26 28 views
1

我有一个功能模块noi-dung.module.ts角2主要成分未加载导入功能模块时,但加载不出口的功能模块组件

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> 

"): [email protected]: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,而不是导出到外部,而不是声明和引导的组件?

[编辑]得到的答案在注释

+0

不知怎的,看起来你有' 载入中... '一个组件,而不是只在里面'index.html' –

+0

@GünterZöchbauer你是对的,在NOI粪-List组件的错字调用错误的模板,所以服务器返回的index.html,谢谢你,我有恐慌花费小时寻找,想到这样并得到答案权利,非常感谢哈哈:D – duc

+0

很高兴听到。是一个相当疯狂的猜测,但错误似乎太奇怪;-) –

回答

1
<body> 
    <my-app>Loading...</my-app> 
</body> 

只应index.html不是在一个组件模板。