I have an Angular 2 application where I am fetching some data from a remote service. My application is layered into a Components layer and a Services layer. The Services layer communicates with the backend services. A sample interaction is posted below:
this.myServiceClass.getData(param1, param2)
.then(res => {
this.responseObj = res;
this.bindDataToGrid();
}
The service getData method returns a Promise where ResponseModel is a View Model class.
The issue is that the statement:
this.responseObj = res;
is throwing an error stating that this is null. So I set it outside the service call as follows:
let this$ = this;
and used this$ in my Promise.then. it works. Question is: It is working for my colleague without the reassignment to this$. For me it is not working even though I am using an arrow function in my code. Any ideas why I need to store a reference to this outside the Promise.then?