2016-06-10 27 views
0

我試圖將輸入參數傳遞給一個組件,但我得到這個異常: browser_adapter.ts:78 EXCEPTION:Error:Uncaught(in promise):No Directive在PropDecoratorFactory在PropDecoratorFactory上找到的Angular2 RC1No指令註解@Input

發現註釋我試圖解決描述here,並沒有解決這個問題對我來說:

這裏是我的代碼:

import {Component, provide, Input} from '@angular/core'; 
import {bootstrap} from '@angular/platform-browser-dynamic'; 
import {Http, HTTP_PROVIDERS} from '@angular/http'; 
import {RouteConfig, ROUTER_DIRECTIVES, Router, ROUTER_PROVIDERS} from '@angular/router-deprecated' 

@Component({ 
    selector: 'sub', 
    template : `<p>input: {{someInput}}</p>`, 
    directives: [Input] 
}) 
export class SubComponent { 
    @Input() someInput: Number; 
} 

@Component({ 
    selector: 'home', 
    template : `<p>home</p><sub [someInput]="someInput"></sub>`, 
    directives: [SubComponent] 
}) 
export class HomeComponent { 
    someInput: Number = 123; 
} 

@Component({ 
    selector: 'my-app', 
    template: '<h1>here!</h1><router-outlet></router-outlet>', 
    directives: [ROUTER_DIRECTIVES], 
    providers: [ROUTER_PROVIDERS] 
}) 
@RouteConfig([ 
    { path: '/home', name: "Home", component: HomeComponent, useAsDefault: true} 
]) 
export class App { 
} 

和我Plunker: http://plnkr.co/edit/wNKmsnjHf6HeCQD1gV8c?p=preview

回答

0

directives陣列行中刪除Input

@Component({ 
    selector: 'sub', 
    template : `<p>input: {{someInput}}</p>`, 
    directives: [Input] // <---- this is causing it 
}) 
export class SubComponent { 
    @Input() someInput: Number; 
} 

輸入不是一個指令,其用於分量輸入一個裝飾只使用了類的內部,而不是在HTML。

+0

哇!這解決了它,非常感謝你! – BSSchwarzkopf

+0

沒問題,'directives'數組只是用於你想在html模板中使用的指令/組件。 –