2016-04-29 32 views
0

我有什麼似乎是一個簡單的問題,我一直試圖解決在學習Angular 2時。創建一個組件,然後將該組件放入根組件。當我不添加其他組件時,頁面加載。當我導入我的自定義組件並將該指令添加到根組件時,頁面將保持加載狀態,並且不會從那裏到達任何地方,就像崩潰一樣。我似乎無法弄清楚。在根組件崩潰的應用程序中的角2自定義組件

我的自定義組件(MY-c.component.ts):

import {component} from 'angular2/core'; 

@component({ 
    selector: 'my-comp', 
    template: ` 
     <h3>Second component</h3> 
    ` 
    }) 

export class mycComponent { 

} 

而現在,這裏的插入我的自定義組件我的 「根」 的組成部分。 (app.component.ts)

import {Component} from 'angular2/core'; 
import {mycComponent} from './my-c.component'; 


@Component({ 
    selector: 'my-app', 
    template: ` 
     <h1>Angular 2 Boilerplate (o yea)</h1> 
     <h2>Now comes the second component</h2> 
     <my-comp></my-comp> 
    `, 
    directives: [mycComponent] 

}) 

export class AppComponent { 

} 

而在我的index.html文件中沒有所有標題的東西,爲了簡單起見。 這不包括polyfills的所有包含,也包括system.config「啓動」應用程序,這些都在那裏。

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

當我拿出我的自定義組件的進口,也拆除指示,我得到這個:

Working without directive in it

這是當我在指令添加發生了什麼[mycComponent]進入根組件。

Not working with directive included :(

這裏的櫃面你想看到它在我的index.html的照片。

index.html

這似乎應該是理解的最簡單的事情和工作之一,但由於某種原因,我卡在這裏。

希望得到任何幫助,爲什麼你認爲它可能無法正常工作:(

文件結構>

File structure

回答

2

難道在你的第二個組成部分的小寫字母「C」 @組件裝飾器?

+0

我花了大約2小時看這個,我從來沒有注意到!我在自定義@Component和更改導入命令導入我的自定義組件的小寫c改爲C是一個小寫的c。剛剛需要這是第二隻眼睛。非常感謝您的幫助! – grimesd

相關問題