var app = angular.module(' myApp',[]);
app.controller('myCtrl', function($scope, $http) {
$http.get("myservice").then(function (response) {
$scope.studentdata = response.data;
});
});
根据学生数据,我需要调用其他服务,如学生地址。如何实现我对角js的新手请帮忙。
答案 0 :(得分:1)
您需要使用保证链来在另一个
之后调用请求 function firstReq(){
return $http({
method: 'POST',
url: 'http://localhost/api/users',
headers: {'Content-Type': 'application/json'},
data: JSON.stringify($scope.user)
})
}
function secondReq(){
return $http({
method: 'POST',
url : 'http://localhost/api/users/' +$scope.user_id + '/accessTokens',
})
}
$scope.processform = function() {
firstReq()
.then( function( response )
{
console.log(response.data.user_id);
$scope.user_id = response.data.user_id;
return secondReq();
})
.then(function(response){
console.log(response.data);
})
}