2017-09-22 14 views
0

我是Angular4的初學者,在我的項目中使用我自己的示例模塊「ex」及其組件「app-ex」時出現問題。我不能在角度上使用模型

瀏覽器記錄此消息:「模板解析錯誤:‘應用程序-EX’是未知元素」

這是我的項目:https://github.com/ndsvw/exampleangular 你只需要

npm install 
npm start 

我試着在我的app.module中聲明ex-component並且它可以工作。但我想導入整個模塊。 有什麼錯?

回答

1

您需要將組件導出到模塊中。當您已將模塊導入模塊時,也不必在模塊中添加模塊。

import { NgModule } from '@angular/core'; 
import { CommonModule } from '@angular/common'; 
import { ExComponent } from './ex.component'; 

@NgModule({ 
    imports: [ 
    CommonModule 
    ], 
    declarations: [ExComponent], 
    exports: [ExComponent] 
}) 
export class ExModule { } 

刪除:

import { Component } from '@angular/core'; 
//import { ExComponent } from './ex/ex.component'; 
//import { ExModule } from './ex/ex.module'; 

@Component({ 
    selector: 'app-root',