[英]$watch does not fire autocomplete ng-model
I have small portion of codes with $watch
but does not fire when a use input with autocomplete ( jQuery plugin). 我只有一小部分使用
$watch
的代码,但是当使用带有自动完成功能的输入(jQuery插件)时不会触发。 it only fires when manual typing input 仅在手动输入时触发
app.directive("autoCode", ['elementData', function(elementData) {
var codes = elementData.map(function(ele){
return ele.Code;
});
return {
restrict: 'A',
scope:{
},
link: function(scope, element, attrs) {
$(element).autocomplete({source:[codes]});
}};
}]);
app.controller('transactionCtrl',['$scope','elementData', function($scope, elementData){
var names = elementData.map(function(ele) {
return ele.Name;
}),
codes = elementData.map(function(ele) {
return ele.Code;
});
$scope.$watch('code', function(codeValue){
console.log(codeValue);
});
}]);
below is html: 下面是html:
<form >
Code: <input type="text" name="code" auto-code ng-model="code">
Name: <input type="text" name="name" auto-name ng-model="name">
</form>
How to make it work with manual typing and autocomplete? 如何使其与手动键入和自动完成功能一起使用?
Try: 尝试:
$scope.$watch($("input[name='code']").length, function(codeValue){
console.log(codeValue);
});
O something like that. 哦,像这样。 You have to put the watch over a value that is changed for many times
您必须将手表放置在多次更改的值上
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.