[英]Angular2 RC1No Directive annotation found on PropDecoratorFactory with @Input
我正在嘗試將輸入參數傳遞給組件,但遇到此異常:browser_adapter.ts:78例外:錯誤:未捕獲(承諾):在PropDecoratorFactory上找不到指令注釋
我嘗試了此處描述的解決方案,但對我來說並沒有解決問題:
這是我的代碼:
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
從directives
數組行中刪除Input
@Component({
selector: 'sub',
template : `<p>input: {{someInput}}</p>`,
directives: [Input] // <---- this is causing it
})
export class SubComponent {
@Input() someInput: Number;
}
Input不是指令,它是組件輸入的修飾符,僅在類內部使用,而不在html上使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.