Double select angular-js ajax

Double select angular-js ajax

本文关键字:ajax angular-js select Double      更新时间:2023-09-26

我试图检索第一个选定值,然后运行ajax调用,以获得基于第一个选定值的第二组数据。

HTML:

<label class="item item-input item-select">
  <div class="input-label">
   Select First:
   </div>
   <select>
    <option  ng-repeat="object in objects" value="object.ID">{{object.value}}</option>
   </select>
</label>
<label class="item item-input item-select">
  <div class="input-label">
   Select 2nd:
  </div>
  <select>
  <option></option>
  </select>
</label>

控制器:

...
dataFactory.getRequestObject(ID).then(function(resp2){
      console.log("Getting data to populate select list!");
      console.log(resp2.data);
      $scope.objects= resp2.data;
    }, function(err){
        console.error('ERROR', err);
    });

其中getRequestObject(ID)是我的函数,它调用我的webservice。

我能够获得我的第一组数据,我想获得第一个的"值",并调用数据的第二个选择列表的检索。我怎么去做呢?

$.getJson(url, param, function(data) {
  $scope.array1 = data.array;
});
$scope.onchange = function() {
  //ng-model will store its value into $scope
  var selectValue1 = $scope.selectValue1;
  
  $.getJson(url2, param2, function(data) {
    $scope.array2 = data.array;
  });
};
<select ng-module="selectValue1" ng-options="label for value in array1" ng-change="onchange()"></select>
<select ng-module="selectValue2" ng-options="label for value in array2"></select>

使用$watch来检测selectValue的变化也会起作用