如何使用angularjs ng-click与html5 datalist [英] How to use angularjs ng-click with html5 datalist

查看:217
本文介绍了如何使用angularjs ng-click与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 不适用于datalist选项,因为click事件(使用datalist时似乎没有触发任何按键事件。

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.

您必须在函数输入 ng-change c $ c>并扩展它以检查当前值是否也存在于datalist中。

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.

这篇关于如何使用angularjs ng-click与html5 datalist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆