我是新來的AngularJS,我需要訪問它的承諾內部分配的Javascript如何訪問內部承諾聲明的變量在AngularJS
this.reqData= this.profileService.getData();
var resp1 = angular.fromJson(this.reqData);
this.data1;
var that = this;
resp1.$promise.then(function (data) {
that.data1= data.resource.resource;
}).catch(function (error) {
console.log(error);
});
console.log(this.data1);
可變數據1從HTML訪問的變量,但它在Javascript中顯示undefined
您不在諾言之外訪問它。你不能從未來獲取價值(除非你創造時間旅行)。 – Bergi