简体   繁体   English

Angular Bootstrap Typeahead下拉菜单

[英]Angular Bootstrap Typeahead dropdown

I have an Angular ui-boostrap typeahead component that is working correctly until I added one requirement to the whole function. 我有一个Angular ui-boostrap typeahead组件,该组件可以正常工作,直到我向整个函数添加了一项要求。 I want to call the backend for the suggested results just after user types in 3 letters. 我想在用户键入3个字母后立即为建议的结果调用后端。 It is done correctly but my problem is that the results are visible only when users type in the 4th letter. 正确完成了,但是我的问题是,只有当用户键入第4个字母时,结果才可见。 Is there any way to bypass this, by forcing it to refresh the UI just after user types in the 3rd letter. 有什么方法可以绕过此操作,方法是在用户键入第三个字母后强制其刷新UI。 Code is : 代码是:

HTLM 
<input name="states" id="states" type="text" ng-model="vm.cityName"
uib-typeahead="municipality as  municipality.city + ' (' + municipality.name + ') '+municipality.zipCode for municipality in vm.getMunicipalitiesByCity($viewValue) | filter:$viewValue | limitTo:8" class="form-control" typeahead-on-select="vm.citySelected()" >

JS Controller
vm.getMunicipalitiesByCity = function (cityName) {
            if (cityName != undefined && cityName.length == 3) {
                CalculationEndpointService.municipalitiesByCity({cityName: cityName}, function (result) {
                    vm.municipalities = result.map(
                        function (item) {
                            return item;
                        }
                    );
                });
            }
            if(cityName.length<3){
                vm.municipalities=[""];
            }
            return vm.municipalities;
        };

you could use typeahead-min-length attribute. 您可以使用typeahead-min-length属性。 see https://angular-ui.github.io/bootstrap/#/typeahead 参见https://angular-ui.github.io/bootstrap/#/typeahead

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM