簡體   English   中英

科爾多瓦插件網絡接口問題

[英]cordova plugin network interface issue

我正在使用離子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);
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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