簡體   English   中英

Angular 2-在內部函數中使用組件變量

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM