【发布时间】:2017-05-20 07:30:04
【问题描述】:
我正在使用 http 调用从后端获取数据。当它登录到浏览器控制台时,我可以看到从后端返回的数据。 但是数据没有分配给类变量。以下是我的代码- “使用严格”;
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”行看到一个错误。 错误是-TypeError:无法设置未定义的属性“数据”。 我没有得到这个问题的解决方案。有人可以帮忙吗?
【问题讨论】:
标签: angularjs http typescript this