2016-12-29 14 views
0

私のAngular 2アプリでは、あるコンポーネントから別のコンポーネントに配列を渡す必要があります。次のように私は、この値を読む必要がInputModuleComponentという名前のコンポーネントで例外self.context.XXX.subscribeは関数ではありません

@Component({ 
    selector: "system-dynamics", 
    templateUrl: "/app/component/main/template/system-dynamics.html" 
}) 

export class SystemDynamicsComponent implements OnInit { 
    private dialogDisplayed: boolean = false; 
    @Output() sdFactors: any[] = []; 

テンプレート:

<system-dynamics (sdFactors)="this.sdFactors"></system-dynamics> 

はコンポーネント:

私は1つのアレイ sdFactorsを公開 SystemDynamicsComponentという名前のコンポーネントを持っています
export class InputModuleComponent implements OnInit { 
... 
sdFactors: any[] = []; 

入力モジュールコンポーネントを起動します。角度からこのエラーメッセージが表示されます。 TypeError: self.context.sdFactors.subscribe is not a function at Wrapper_SystemDynamicsComponent.subscribe (wrapper.ngfactory.js:38) at View_InputModuleComponent6.createInternal (component.ngfactory.js:3103) at View_InputModuleComponent6.AppView.create (core.umd.js:12262) at View_InputModuleComponent6.DebugAppView.create (core.umd.js:12666) at TemplateRef_.createEmbeddedView (core.umd.js:9320) at ViewContainerRef_.createEmbeddedView (core.umd.js:9552)

アイデアは何ですか?

答えて

2

ではなく、あなたが結合するためのテンプレートでthisを追加する必要がいけない

<system-dynamics (sdFactors)="this.sdFactors"></system-dynamics> 

のこの

<system-dynamics (sdFactors)="sdFactors"></system-dynamics> 

試してみてください。同じクラスの変数には、thisをテンプレートにアクセスすることなくアクセスできます。

@outputイベントがプロパティが結合のためではない結合のために使用されているアップデート、あなたはとてもこの

<system-dynamics [sdFactors]="sdFactors"></system-dynamics> 

のようにこれを使用すると、このようなあなたのコンポーネントにpassign配列またはいくつかの変数の値を@inputを使用する必要があります

@Component({ 
    selector: "system-dynamics", 
    templateUrl: "/app/component/main/template/system-dynamics.html" 
}) 

export class SystemDynamicsComponent implements OnInit { 
    private dialogDisplayed: boolean = false; 
    @Input() sdFactors: any[] = []; 
+0

提案した( ')のように変更しましたが、問題は残ります。 – Emdee

+0

私の更新を参照してください –

+0

問題が解決しました!私はあなたが提案したように '@ Input'を使用します。 – Emdee

関連する問題