给定一个服务的ID,使用AngularJS从另一个JSON获取数据
我是AngularJs的新手,我正在尝试从两个不同的JSON返回服务获取数据。给定一个服务的ID,使用AngularJS从另一个JSON获取数据,angularjs,Angularjs,我是AngularJs的新手,我正在尝试从两个不同的JSON返回服务获取数据。 我有一个列表,从一个服务中获得,其中我显示了用户ID。 这是可行的,但我需要的是,给定该用户ID,从另一个JSON获取该用户的名字和姓氏。 我怎么做?欢迎任何帮助 这是AngularJs(1.6)控制器: controller('myReservations',function($scope,$http){ $scope.reserve = []; $scope.sId = s; $http.
我有一个列表,从一个服务中获得,其中我显示了用户ID。
这是可行的,但我需要的是,给定该用户ID,从另一个JSON获取该用户的名字和姓氏。
我怎么做?欢迎任何帮助 这是AngularJs(1.6)控制器:
controller('myReservations',function($scope,$http){
$scope.reserve = [];
$scope.sId = s;
$http.get('/reserve/').then(
function(response){
$scope.reserve = response.data.description;
},
function(response){
console.log(response.statusText);
}
);
})
以及HTML:
<ul class="reservationsList" ng-controller="myReservations">
<li ng-repeat="res in reserve | filter: {ideventroom: sId}">
User: {{res.iduser}} <br>
First name: <!-- Here goes the first name --><br>
Last name: <!-- Here goes the last name -->
</li>
</ul>
在“/user/2”中,我得到:
谢谢大家! 您可以将第二个功能链接到第一个功能上。在该函数中,您可以使用现在可用的用户ID发出其他http请求
{
"status": 0,
"description": [
{
"id": 1,
"ideventroom": 3,
"iduser": 2
},
{
"id": 2,
"ideventroom": 3,
"iduser": 1
}
]
}
{
"status": 0,
"description": [
{
"id": 2,
"firstname": "John",
"lastname": "Smith",
"email": "johnny@smithy.co",
"phone": "11111111"
}
]
}