假设我在选择标签中有两个酒店,我希望我的h1在选择其中一个选项时进行更改。我如何实现这一点如何在选择选项时从API动态调用数据
我正在使用POST方法授权和调用我的reservationCtrl中的数据并在我的select标签中显示hotel_name。
<div class="container">
<div class = "row" ng-controller="reservationCtrl">
<div class="form-group">
<label for="sel1">Select a Hotel:</label>
<select class="form-control" id="sel1">
<option ng-repeat="x in hotels.data">{{x.hotel_name}}</option>
</select>
</div>
</div>
而我正在使用GET方法从另一个API调用数据来显示hotel_name。
<div class="row" ng-controller="showCtrl">
<div class="col-md-4">
<h1 ng-repeat="x in hotel.data">{{x.hotel_name}}</h1>
</div>
</div>
</div>
这是我showController,我想我的酒店ID改变就像从72到35,当我点击其中的一个选项,这样它会从不同的API调用的数据,并在报头显示不同的名字。
(function(){
angular
.module("reservationModule")
.controller("showCtrl", function($http, $scope, $log){
$http({
method: 'GET',
url: '&hotel_id=72'})
.then(function (response) {
$scope.hotel = response.data;
}, function (reason){
$scope.error = reason.data;
$log.info(reason);
});
});
})();
这里是reservationController
(function(){
angular
.module("reservationModule")
.controller("reservationCtrl", function($http, $scope, $log){
$http({
url: '',
method: "POST",
data: 'postData',
headers:{ 'Authorization': 'value'}
})
.then(function(response) {
$scope.hotels = response.data;
}
);
});
})();
可以在选择选项 –