Utilizing an http call to fetch data from the backend, I am able to see the retrieved data in the browser console. However, for some reason, the data is not being assigned to the class variable as expected. The code snippet is shown below: "use strict";
export class EditTranslationsController {
static IID: string = "EditTranslationsController";
static $inject: string[] = ["$http", "$scope", "$log"];
private _welcome : string = "HELLO WORLD!";
public data : any;
constructor(private $http: angular.IHttpService,
private $log: angular.ILogService,
private $scope: angular.IScope) {
this.sendUpdatedData();
}
public sendUpdatedData = () => {
this.$http({
method : 'POST',
url : '/test'
}).then(function successCallback(response) {
console.log(response.data);
this.data = response.data;
}, function errorCallback(response) {
this.$log.error(response);
});
}
}
While debugging the code, an error occurs at the line 'this.data=response.data'. The error message reads: TypeError: Cannot set property 'data' of undefined. I have been struggling to find a solution to this issue. Can anyone offer assistance?