2017-03-14 3 views
0

私はbg boostrap modalを使用しています。テンプレート内で宣言されている変数のコンポーネントへのアクセス

私は

<button (click)="open(content)">Launch demo modal</button> 

のみを考慮して定義されcontentオブジェクトへのアクセスを有することボタンopen方法は、コンポーネントで定義されているが、contentオブジェクトは、テンプレートに存在します。

this.open(accessContentHere)はどのようにして私のコンポーネントの中から呼び出すことができますか?

答えて

0

これには、ViewChildデコレータを使用できます。あなたのコンポーネントで、ViewChildをインポートして、template local variableの名前をパラメータに設定します。

import {..., Component, OnInit, ViewChild } from '@angular/core' 

... 

export class YourComponent extends Component implements OnInit { 
    @ViewChild('content') content; 

    ngOnInit() { 
     this.open(content); 
    } 

    open(myContent) { //...} 

    ... 

} 
関連する問題