我正在使用离子2
从https://github.com/salbahra/cordova-plugin-networkinterface下载了插件
不能使用任何全局变量或调用该函数内的任何其他函数
networkinterface.getIPAddress(function (ip) { alert(ip);});
如果我使用这样的东西
networkinterface.getIPAddress(function (ip)
{ alert(ip);
this.test(ip); });
test(x){
console.log("IP = "+ x);}
我收到一个错误:
成功中的错误callbackId:networkinterface1280836273:TypeError:无法读取null的属性“ test”。
我可以正确收到Ip警报,但是无法在提供的功能之外访问它。另外,typerscript也会给出错误:
[ts]找不到名称“网络接口”。
当我使用插件时。但是它仍然可以编译和运行。
知道如何解决该问题吗?
解决了(由于离子共同体),需要使用lambda函数=>
从周围环境中捕获其含义。更多信息在这里
loadIPAddress() {
networkinterface.getIPAddress((ip) => {
alert(ip);
this.test(ip);
});
}
test(x) {
console.log("IP = "+ x);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句