是否有触发打开来自控制器的“提前输入”文本框上的匹配结果?
用例:
显然,在输入文本框时,我似乎只能得到提前输入的结果。
发布于 2016-12-08 02:06:37
我让它在几个方面发挥作用,但两者都需要修改ui引导程序。我想我可以创建一个拉请求,但不确定我的特定用例是否是一个常见的用例。
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);
});
}
}更新到ui引导程序:
this.exportScheduleSearchWithTimeout = function(inputValue) {
return scheduleSearchWithTimeout(inputValue);
};坏:要求在控制器上公开该方法。唯一可用的方法是隔离init方法和作用域。不是从外部控制器打来的。
2)添加新的类型提前属性以允许设置默认值并在焦点上显示结果:
更新到ui引导程序:
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
https://stackoverflow.com/questions/41026831
复制相似问题