如何在 select 选择一个选项后从 ui-select 移除焦点

How to remove focus from ui-select after selecting an option

一旦用户使用鼠标单击 select 编辑了一个选项并在 enter 上开始搜索,我需要从 ui-select 输入中移除焦点。现在发生的事情是焦点仍然在 select 上,结果下拉列表在单击 enter 时打开。

  <ui-select id= "country" ng-model="ctry" name= "country"  theme="bootstrap">
      <ui-select-match >{{text || $select.selected.id}}</ui-select-match>
          <ui-select-choices repeat="countryL in countryLookup | filter: $select.search">
             <div ng-bind-html="countryL.id | highlight: $select.search"></div>
                <small ng-bind-html="countryL.name | highlight: $select.search"></small>
       </ui-select-choices>

将 on-select="onSelected($item)" 添加到您的 ui-select 和控制器中:

$scope.onSelected = function (selectedItem) {
    setTimeout(function(){
        $(':focus').blur();
    })
}

或在控制器中使用 $timeout

从版本 v0.14.9 开始,您可以将 skip-focusser 设置为 true 以在选择项目后跳过聚焦器。

以下对我有用;

$timeout(function() {
    angular.element(document.activeElement).blur();
});

$timeout(function() {
    angular.element($document[0].activeElement).blur();
});