本文介绍了Anular5-“此”在ready()中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个graph.component.ts
I have a graph.component.ts
this.cContainer = cytoscape ( { ready: function(e) { this._dataService.setResultData(); } });
但我得到
错误TypeError:无法读取属性'setResultData 'of undefined
.. so this 似乎是未知的,看起来是正确的因为我在回调中,所以 称为就绪回调。
..so this seems to be unknown, which looks correct because I am within a callback and so this is referred to the ready-callback.
但是我怎么从这个 ready()内部调用 _dataService.setResultData() -callback?
but how would I call _dataService.setResultData() from inside this ready()-callback?
推荐答案
使用箭头功能从捕获此声明上下文。对于函数 ,这由调用者确定,可能不是您的课程:
Use an arrow function to capture this from the declaring context. For function this is determined by the caller and will probably not be your class:
this.cContainer = cytoscape ( { ready: (e) => { this._dataService.setResultData(); } });
这篇关于Anular5-“此”在ready()中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!