UI Bootstrap Typeahead忽略选定的值

时间:2022-02-01 11:07:44

I'm using Ui-Bootstrap's Typeahead. I have two Typeahead fields (Origin and Destination Airport) and both takes the same data source. I want to avoid the Origin selected value in Destination listing. How can I do that?

我正在使用Ui-Bootstrap的Typeahead。我有两个Typeahead字段(Origin和Destination Airport),两者都采用相同的数据源。我想避免目的地列表中的原始选定值。我怎样才能做到这一点?

Origin

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

Destination

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

I found in Google to do something like

我在谷歌找到了类似的东西

ng-if="person.name_key!='FirstPerson'"

in the ng-repeat element but here I have no access for ng-repeat in the HTML.

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

Please help.

1 个解决方案

#1


1  

You can use typeahead-on-select($item) to execute a callback that will remove the selected item from the data array like this:

您可以使用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)">

And as for the onSelect function -

至于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);
  };

Here's a working plunker

这是一个工作的plunker

#1


1  

You can use typeahead-on-select($item) to execute a callback that will remove the selected item from the data array like this:

您可以使用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)">

And as for the onSelect function -

至于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);
  };

Here's a working plunker

这是一个工作的plunker