Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度解析获取返回_Angularjs - Fatal编程技术网

Angularjs 角度解析获取返回

Angularjs 角度解析获取返回,angularjs,Angularjs,m通过以下请求在工厂中生成: var m = $http({method: 'GET', url: JSONurl}); GET请求后的m控制台日志: 我需要抓取m的“数据:”它有我需要的数组[2]。如何仅使用数据数组创建一个新变量?如果您查看angularJS,就会发现您需要使用promise来获取数据。所以你想要的东西大致如下: $http({ method: 'GET', url: JSONurl }).then(function successCallback(respo

m
通过以下请求在工厂中生成:

  var m = $http({method: 'GET', url: JSONurl});
GET请求后的
m
控制台日志:


我需要抓取
m
的“数据:”它有我需要的
数组[2]
。如何仅使用数据数组创建一个新变量?

如果您查看angularJS,就会发现您需要使用promise来获取数据。所以你想要的东西大致如下:

$http({
  method: 'GET',
  url: JSONurl
}).then(function successCallback(response) {
    //response has the data on a successful call
  }, function errorCallback(response) {
    //this response will have the error data on a failed call
  });

如果您查看angularJS,就会发现您需要使用promise来获取数据。所以你想要的东西大致如下:

$http({
  method: 'GET',
  url: JSONurl
}).then(function successCallback(response) {
    //response has the data on a successful call
  }, function errorCallback(response) {
    //this response will have the error data on a failed call
  });
m.then(res=>res.data)
m.then(res=>res.data)