2016-04-26 194 views
0

剛開始使用angular2-seed應用的角度2:https://github.com/angular/angular2-seed。我創建了一個組件,但它不會顯示在頁面上,該組件坐落在一個目錄處於同一水平的部件叫做external_components:如何以角度2顯示組件?

import {Component} from 'angular2/core'; 

@Component({ 
    selector: 'SiteQualification', 
    template: '<div>hello service external</div>', 
}) 
export class SiteQualification { 

    constructor() {} 

    ngOnInit() { 

    } 

} 

這是種子app.ts:

import {Component} from 'angular2/core'; 
//import {Router, RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router'; 

import {Home} from './components/home/home'; 
import {About} from './components/about/about'; 
import {SiteQualification} from './external_components/sitequalification'; 
import {RepoBrowser} from './components/repo-browser/repo-browser'; 

@Component({ 
    selector: 'seed-app', 
    providers: [], 
    pipes: [], 

    templateUrl: 'app/seed-app.html', 
}) 

export class SeedApp { 

    constructor() { 
    } 

} 

在種子app.html我有:

<main> 
    <siteQualification></siteQualification> 
</main> 

這是app.ts:

import {bootstrap} from 'angular2/platform/browser'; 
import {provide} from 'angular2/core'; 
import {HTTP_PROVIDERS} from 'angular2/http'; 
import {ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy} from 'angular2/router'; 

import {SeedApp} from './app/seed-app'; 


bootstrap(SeedApp, [ 
    HTTP_PROVIDERS, 
    ROUTER_PROVIDERS, 
    provide(LocationStrategy, {useClass: HashLocationStrategy}) 
]) 
.catch(err => console.error(err)); 

也刪除了路由器。 問題是組件不會顯示?我錯過了什麼?

+0

是否有一個控制檯錯誤?你是否引導你的主應用程序? – echonax

+0

選擇器是SiteQualification,標籤是siteQualification。這不是問題嗎? –

+0

@echonax沒有控制檯錯誤 –

回答

0

你需要列出在那裏它們被用在組件的directives: [...]列表組件和指令:

@Component({ 
    selector: 'seed-app', 
    directives: [SiteQualification], 
    ... 
}) 
+1

嘿工作!!謝謝。 –