![](/img/trans.png)
[英]Angular: How can I access Child Component template variable in parent Component?
[英]How can I get access to a template generated local variable to component code?
也許我在想完全錯誤的方向。 但是我想做的是在組件中調用模板中定義的變量的值。
<button (click)="download()">...</button>
<ng-container *ngIf="objectlist | filterSort: sortColumnService.sortTerm() as filteredSkaterlist">
...
</ng-container>
有什么干凈的方法可以訪問組件的 function 中的filteredSkaterlist
嗎? 將filteredSkaterlist
作為參數發送,例如click()
不是一個選項,因為按鈕不在 scope 之內。
@Component({...})
export class MyComponent {
...
download() {
// access value of filteredSkaterlist
}
}
你能試試這個方法嗎?
<ng-container *ngIf="objectList()">
...
</ng-container>
我已經用 *ngIf 的結構指令定義了 objectList() 方法。 我們可以在組件 class 中定義 objectList() 方法,並根據條件返回 true 或 false。
@Component({...})
export class MyComponent {
objectList() : boolean {
// access value class objects and return true false value
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.