0

I'm using cordova AppCenter Shared plugin inside Ionic4 app and calling function, I was able to get ID in console, but cannot assign it to public variable, any ideas?:

Stack: Angular 6

public deviceId: string = '';

this._window.AppCenter.getInstallId(function(success, error) {
          console.log(success);
          this.deviceId = success;        
      });
devhustler
  • 51
  • 2
  • 9
  • Possible duplicate of [How to access the correct \`this\` inside a callback?](https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback) – ConnorsFan Oct 31 '18 at 14:46

2 Answers2

2
this._window.AppCenter.getInstallId(success => {
      console.log(success);
      this.deviceId = success;        
});

For more detail, read this

Harun Or Rashid
  • 5,589
  • 1
  • 19
  • 21
1

You need to use arrow function in this case, because using this refers to the function context.

this._window.AppCenter.getInstallId(success => {
     this.deviceId = success;        
});

You can refer the answer here

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396