如何使用指令和引用元素更改模型?

时间:2014-11-12 19:49:31

标签: javascript jquery angularjs

我的页面中有一个文本框,其中包含自定义自动完成指令:

<input type="text" auto-complete ng-model="variant" value="{{variant}}"/> 

我遇到的问题是,当用户从自动完成菜单中选择一个值时,ng-model不会更新。

我决定在ng-blur指令中更改模型。我试过了:

<input type="text" auto-complete ng-blur="variant=element.value" ng-model="variant" value="{{variant}}"/> 

那不起作用。有没有办法在不编写自定义指令的情况下完成此任务?

1 个答案:

答案 0 :(得分:0)

试试这个:

<input type="text" auto-complete ng-blur="variant=$event.target.value" ng-model="variant" value="{{variant}}"/>

这是 working demo