1
httpコールを使用してバックエンドからデータを取得しています。私はそれがブラウザのコンソールにログインすると、バックエンドから戻ってくるデータを見ることができます。 しかし、データはクラス変数に割り当てられません。以下は私のコードです "use strict";Typescript:クラス変数にデータが割り当てられていません
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);
});
}
}
コードをデバッグすると、「this.data = response.data」という行にエラーが表示されます。 エラーis-TypeError:プロパティ 'data'を未定義に設定できません。 この問題の解決方法はありません。誰か助けてもらえますか?