我的输入字段包含ng-model =" searchJob"我正在使用自动完成插件。我也有一个名为ng-enter的指令。但是当我从输入击键中选择值时,它会触发指令,并且我不会从该字段中获取更新的值。我期待一个解决方案。
<input ng-model="searchJob" type="text" id="suggest" class="form-control search-input" placeholder="Search your desired job" ng-enter="search(searchJob)" autofocus/>
我的指令代码:
jobApp.directive('ngEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event, ui) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.ngEnter, {'event': event});
});
event.preventDefault();
}
});
}});
jquery自动填充代码
$(document).ready(function(){
$("input").autocomplete({
delay: 100,
minLength: 2,
source: function (request, response) {
var suggestURL = "someUrl"+$('input').val();
$.ajax({
method: 'GET',
dataType: 'json',
url: suggestURL
})
.success(function(data){
response(data);
});
},
select: function (event, ui) {
event.preventDefault();
console.log(ui.item.value);
angular.element($('#suggest').val(ui.item.value)).triggerHandler('input');
return false;
}
});
});