UI Bootstrap Typeahead 忽略所选值

UI Bootstrap Typeahead ignore selected value

我正在使用 Ui-Bootstrap's Typeahead。我有两个 Typeahead 字段(始发地和目的地机场)并且都采用相同的数据源。我想避免在 Destination 列表中选择 Origin 值。我该怎么做?

来源

<input type="text" ng-model="orig" typeahead="s in data | filter:$viewValue" class="form-control input-lg">

目的地

<input type="text" ng-model="dest" typeahead="s in data | filter:$viewValue" class="form-control input-lg">

我在 Google 中发现可以做类似

的事情
ng-if="person.name_key!='FirstPerson'"

在 ng-repeat 元素中,但在这里我无法访问 HTML.

中的 ng-repeat

请帮忙。

您可以使用 typeahead-on-select($item) 执行回调,从数据数组中删除所选项目,如下所示:

    <input type="text" ng-model="orig" typeahead="s for s in data | filter:$viewValue" 
           class="form-control input-lg" typeahead-on-select="onSelect($item)">

至于 onSelect 函数 -

  $scope.onSelect = function(item){
    $scope.data.push($scope.previouslySelected); // push back the previously selected
    $scope.previouslySelected = item; // save the currently selected
    var index = $scope.data.indexOf(item);
    $scope.data.splice(index, 1);
  };

这是一个有效的 plunker