[英]How to get a reference to a particular component in an Angular2 template?
[英]How do you reference “this” in an Angular2 component template?
我有一個Angular2組件:
class A {
filter(..)
}
在A的模板中,我有
<.. list | pipe:filter ..>
管道內部我調用filter,問題是我沒有引用“this”,因為JS是動態范圍的,當我調用它時,我無法訪問過濾器內部的A實例變量。 有沒有辦法獲得“這個”參考?
如果需要在管道中引用“this”,則可能必須將組件的屬性設置為“this”
export class Component() {
that = this;
}
然后將“that”作為過濾器中的參數傳遞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.