我已经在pubInfoKey上编写了监视,但是当我在select函数中将值设置为pubInfoKey时它无法正常工作。这里可能出现什么问题,我想在pubInfoKey值改变上调用Controller changeState方法
指令的链接功能:
link: function(scope, element, attrs, ngModelCtrl, state) {
var pubInfoKey;
scope.$watch('pubInfoKey', function(val) {
if (val) {
$scope.changeState(val);
}
}
);
var autoSuggest = element.autocomplete({
select: function(event, ui) {
var i = 0;
for (i = 0; i < scope.sug.length; i++)
{
if (scope.sug[i] === ui.item.value.toString())
{
pubInfoKey = scope.suggestionKey[i];
break;
}
}
}
});
}
控制器:
$scope.sug = [];
$scope.suggestionKey = [];
$scope.changeState = function(value) {
//some code
};
答案 0 :(得分:1)
SyntaxError: Unexpected token }
pubInfoKey
成为scope
$digest
:var autoSuggest = element.autocomplete({
select: function(event, ui) {
var i = 0;
for (i = 0; i < scope.sug.length; i++) {
if (scope.sug[i] === ui.item.value.toString()) {
scope.$apply(function(){
scope.pubInfoKey = scope.suggestionKey[i];
})
break;
}
}
}
});