2015-09-27 74 views
0
JSON URL : https://api.github.com/users/odetocode 

此json url包含另一个json数据的url。我怎么可以从这个网址打到另一个URL来获得数据并将其取到HTML如何从角js的其他json网址获取json url

var app = angular.module('ionicApp', ['ionic']); 

app.controller('MainCtrl', function($scope, $ionicModal,$http) { 
    var url = "https://api.github.com/users/odetocode?callback=JSON_CALLBACK"; 
$http.jsonp(url) . 
    success(function(post, status, headers, config) 
    { $scope.data = post; 
    $scope.users= post.data; 
    $scope.followers_url= post.data.followers_url; 
    }) . 
    error(function(data, status, headers, config) { 
    alert("no data found"); 

    }); 

}); 

如何我可以从角JS这个JSON文件打另一个URL。如果我想检查这个用户有多少追随者和追随者。如何我可以做到这一点。

+1

你为什么要出示 –

+0

我不是大喊,我只是问一个问题的帮助.. –

+1

所有封面,在印刷中,大声呼喊 –

回答

0

有没有这样的事情被称为JSON网址。你所拥有的是一个url,它在请求时返回json表示的内容。无论如何,您可以在第一次请求的成功回调中调用第二个url。像下面这样:

$http.jsonp(url).success(function(post, status, headers, config) { 
    // ... 
    // you can make a second $http call here, 
    // but it is nicer to sequence a call to another 'then' (see below) 
}) 

我会建议你使用then而不是successerror,被弃用的角度1.4.4:

$http.jsonp(url) 
    .then(function (httpResponse) { 
     // the body of the http call is in httpResponse.data 
     // ... 
     return nextObject; 
    }) 
    .then(function (data) { 
     // make call to the followers url 
    }) 
    .catch(function (error) { 
     // handle errors 
    }); 

第一返回的对象那么回调函数(这里是nextObject),将是第二个输入数据,然后是回调函数