如何以角度存储http结果



无法从其他问题中找到答案。

我正在尝试从 Web 服务获取数据,然后绘制图表并在其下方显示一个表格。

如果我将数据表放在 .then 函数中,它会抛出错误。所以我的想法是将结果存储在 json 变量中并使用 fromSource 加载它。

现在的问题是我可以看到def.promise,但是当我尝试访问.value时,它显示"未定义"。

知道吗?

app.controller('abc', function($scope, $q, $http){
 var def = $q.defer();
$http.get(API).then(function(result){
  def.resolve(result);
  //draw a chart
});
console.log(def.promise.$$state.value); //returns undefined. 
console.log(def.promise); 
//returns:
//d {$$state: Object, then: function, catch: function, finally: function}$$state: Objectstatus: 1value: Array[39]0: //Object1: Object2:
 $scope.dtOptions = DTOptionsBuilder.fromSource(angular.toJson(def.promise.$$state.value));
});

好吧,我想通了...

您可以使用 fromFnPromise,而不是使用 fromSource 来引用数据表的数据。

最新更新