如何在 html5 数据列表中使用 angularjs ng-click [英] How to use angularjs ng-click with html5 datalist
问题描述
我正在使用 AngularJS,我想在选择数据列表 (html5) 的元素时使用指令 ng-click
.
I'm working with AngularJS and i want to use the directive ng-click
when an element of a datalist (html5) is selected.
这是我的实际代码示例:
Here is an example of my actual code:
<label>Search</label>
<input type="text" class="input-search" list="datalistcit" ng-change="changeQuery(queryCity)" ng-model="queryCity" />
<datalist id="datalistcit">
<option ng-repeat="city in cities" ng-click="goCity(city)" value="{{city.name}}">
</option>
</datalist>
它不起作用,永远不要执行 js 方法 goCity.. 有什么想法吗?
It doesn't work, never execute the js method goCity.. any idea?
推荐答案
ng-click
对数据列表选项不起作用,因为单击事件(也不是任何按键事件)都不起作用使用数据列表时似乎被解雇.
ng-click
won't work on datalist options, as the click event (nor any of the keypress events) doesn't seem to be fired when using the datalist.
您必须在函数 input
上使用 ng-change
并扩展它以检查当前值是否也存在于数据列表中.
You will have to use your ng-change
on the function input
and extend that to check if the current value is also present in the datalist.
这篇关于如何在 html5 数据列表中使用 angularjs ng-click的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!