How to access class variable inside Promise then() function? [duplicate] How to access class variable inside Promise then() function? [duplicate] typescript typescript

How to access class variable inside Promise then() function? [duplicate]


If you pass a function reference, this won't point to the local class instance anymore.

You can use bind

.then(this.extractData.bind(this))

or arrow functions

.then((res) => this.extractData(res))

to get the desired behavior.