0
我正在使用bg boostrap模式。在組件中訪問在模板中聲明的變量
我有具有訪問content
對象的按鈕僅被定義在視圖
<button (click)="open(content)">Launch demo modal</button>
open
該方法是在組件中定義,但content
對象僅在模板存在。
如何從組件內部撥打this.open(accessContentHere)
?
我正在使用bg boostrap模式。在組件中訪問在模板中聲明的變量
我有具有訪問content
對象的按鈕僅被定義在視圖
<button (click)="open(content)">Launch demo modal</button>
open
該方法是在組件中定義,但content
對象僅在模板存在。
如何從組件內部撥打this.open(accessContentHere)
?
你可以使用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) { //...}
...
}