发生此问题是因为模糊事件在'data.country'中的值更新之前触发,您可以使用下面的代码来解决此问题。创建类似如下─
angular.module('app', []).directive('easyAutoComplete', function() {
return {
restrict: 'A',
require: 'ngModel',
priority: 1, // needed for angular 1.2.x
link: function(scope, elm, attr, ngModelCtrl) {
var options = {
url: "https://api.myjson.com/bins/1rjn5",
getValue: "country",
listLocation: "data",
list: {
match: {
enabled: true
},
onChooseEvent: function() {
scope.$apply(function() {
ngModelCtrl.$setViewValue($(elm).getSelectedItemData().country);
});
}
},
};
$(elm).easyAutocomplete(options);
}
};
});
然后用它像作为指令 -
<input type="text" ng-model="data.country" easy-auto-complete ng-change="FindMaterialDetail(data.country)" id="Autocomplete">
你必须定义'data':'$ scope.data = {};' –
不解决问题,还是一样。更新小提琴https://jsfiddle.net/zvezrg6j/2/ –
它只会显示输入值的类型,因为当您从列表中选择选项时,输入字段失去了焦点与最后一个类型的值。在此操作之后,ngblur事件不会被触发。 – rraman