2016-03-31 19 views
1

誰かがどこかで私を指し示すことができますか(ここで説明してください)、ベータ版の出力についてもっと知ることができますか?12入力と出力を正しく使用する方法を知りたいと思います。私は入力に自信がありますが、出力を実装する方法についてもっと知りたいと思います。Angular2 beta.12の入力と出力(以前のプロパティとイベント)

+1

@Component({ selector: 'my-child', template: '<button (click)="clicked.emit($event)">{{label}}</button>' }) class ChildComponent { @Input() label: string; @Output() clicked: EventEmitter; } 
Angular2クックブック - [コンポーネントの相互作用(https://angular.io/docs/ts/latest/cookbook/component-communication .html) – Abdulrahman

+1

https://angular.io/docs/ts/latest/guide/template-syntax.html#!#inputs-outputs –

答えて

1

コンポーネントは、入力から親からデータを受け取ります。それは出力を通して親にデータを送り返すことができます。

親コンポーネント:

@Component({ 
    selector: 'my-parent', 
    template: '<my-child [label]="buttonLabel" (clicked)="handleClick()"></my-child>', 
    directives: [ChildComponent] 
}) 
class ParentComponent { 
    buttonLabel = 'Very Important Button'; 
    handleClick() { 
    console.log('The button in the child component was clicked!'); 
    } 
} 

子コンポーネント:

+0

これは、 'inputs 'を' @Component'に入れることと同じです() 'たとえば' @Component({ セレクター: "my-app"、 テンプレート: "

こんにちは

"、 入力:[ "MYPROPERTY"] }) ' 私は私の他のコンポーネントのため、' <私のアプリは、[MYPROPERTY] =何か> ' は相当があります出力のために 'outputs = [...]'をデコレータに入れて、クラスではないようにします –

+0

はい、 '@ Component'のオブジェクトは' outputs'プロパティを持つことができます。 (Angular 2の[ComponentMetadataのドキュメント](https://angular.io/docs/js/latest/api/core/ComponentMetadata-class.html)を参照してください) – eppsilon

関連する問題