UI Bootstrap Typeahead忽略选定的值

时间:2015-07-06 19:22:37

标签: angularjs angularjs-ng-repeat angular-ui-bootstrap typeahead.js

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

来源

<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。

请帮忙。

1 个答案:

答案 0 :(得分:1)

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

相关问题