Typeahead AngularStrap:$http调用太多



我使用angularstrap typeahead通过$http自动完成建议。在这里演示。

 <input type="text" class="form-control" ng-model="selectedAddress" data-animation="am-flip-x" bs-options="address.formatted_address as address.formatted_address for address in getAddress($viewValue)" placeholder="Enter address" bs-typeahead>

一切都很好,但每次我打一封信,就会接到一个电话。即使我将minLength设置为3,也会调用长度1和长度2。

我该如何防止这种行为?发生的另一件事是,当加载模板/控制器时,会调用函数getAddress。。。

使用ng模型选项作为属性:

ng-model-options="{ debounce: 2000 }"

此代码将帮助您仅每隔1秒拨打一次电话。即使您在此期间键入4-5个字符,它仍然每2秒只调用一次。

最新更新