Cordova plugin - network interface issue

You should use arrow functions (AKA lambda functions in TS) to capture the meaning of this from the surrounding context (as @rapropos wanted to hint you above I guess). You’ll find a good explanation about this in the TypeScript documentation. In the context of your code sample it means to change it this way:

export class Test {
  // ...
  function loadIPAddress() {
    networkinterface.getIPAddress((ip) => {
      alert(ip);
      this.test(ip);
    });
  }

  function test(x) {
    console.log("IP = "+ x);
  }
  // ...
}
2 Likes