![](/img/trans.png)
[英]How to access component class variables inside a callback function in angular?
[英]Angular 2 - using component variables inside inner function
假設我具有以下功能:
ifvisible.now("idle", function(){
// Stop auto updating the live data
if (this.activitySub)
this.activitySub.unsubscribe();
});
由於無法識別function() { }
中的所有變量,如何在函數內部(或以任何其他方式)導入或使用它們?
試試這個Arrow Functions
,未經測試,但可能適合您:-
ifvisible.now("idle", () => {
...your code...
});
通過使用箭頭功能
也可以看看
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.