回答

0

我知道它在几个方面工作,但都需要更改ui-bootstrap。我想我可以创建一个拉取请求,但不确定我的特定用例是否常见。

1)自定义指令并调用UibTypeaheadController.scheduleSearchWithTimeout方法在输入元素的焦点上。

指令:

.directive("showSearchResultsOnFocus", function($stateParams) { 
return { 
    require: ['uibTypeahead', 'ngModel'], 
    link: function (scope, element, attr, ctrls) { 
     var typeaheadCtrl = ctrls[0]; 
     var modelCtrl = ctrls[1]; 

     element.bind('focus', function() { 
      if (!$stateParams.search || !modelCtrl.$viewValue) return; 
      typeaheadCtrl.exportScheduleSearchWithTimeout(modelCtrl.$viewValue); 
     }); 
    } 
} 

更新到用户界面的自举:

this.exportScheduleSearchWithTimeout = function(inputValue) { 
    return scheduleSearchWithTimeout(inputValue); 
}; 

坏:需要在控制器制作方法公开。只有可用的方法是init方法和范围是孤立的。不打算从外部控制器打电话。

2)添加新的预输入属性,让焦点设置默认值并显示结果:

更新到用户界面的自举:

var isAllowedDefaultOnFocus = originalScope.$eval(attrs.typeaheadAllowDefaultOnFocus) !== false; 
originalScope.$watch(attrs.typeaheadAllowedDefaultOnFocus, function (newVal) { 
    isAllowedDefaultOnFocus = newVal !== false; 
}); 

element.bind('focus', function (evt) { 
    hasFocus = true; 
    // this was line before: if (minLength === 0 && !modelCtrl.$viewValue) { 
    if ((minLength === 0 && !modelCtrl.$viewValue) || isAllowedDefaultOnFocus) { 
    $timeout(function() { 
     getMatchesAsync(modelCtrl.$viewValue, evt); 
    }, 0); 
    } 
}); 

坏:拉请求UI的引导,但变化也许不是一个常用的功能。在这里提交了一个PR:https://github.com/angular-ui/bootstrap/pull/6353不知道是否会合并或不使用,直到那时使用分叉。

其他建议?

版本 角:1.5.8,UIBS:2.2.0,引导:3.3.7