Angular Bootstrap Typeahead下拉列表

时间:2016-07-28 09:19:00

标签: javascript angularjs angular-ui-bootstrap typeahead angular-digest

我有一个Angular ui-boostrap typeahead组件正常工作,直到我向整个函数添加了一个要求。我想在用户输入3个字母后立即调用后端的建议结果。这是正确完成但我的问题是只有当用户键入第4个字母时结果才可见。有没有办法绕过这个,通过强制它在用户输入第三个字母后刷新UI。 代码是:

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;
        };

1 个答案:

答案 0 :(得分:0)

您可以使用typeahead-min-length属性。见https://angular-ui.github.io/bootstrap/#/typeahead