在angularjs如何访问触发事件的元素? [英] in angularjs how to access the element that triggered the event?
问题描述
我同时使用引导和AngularJS在我的web应用程序。我有一些困难得到两个一起工作。
我有一个元素,它具有属性数据提供=预输入
<输入ID =SEARCHTEXTNG模型=SEARCHTEXT类型=文本
类=输入搜索中查询占位=标题
数据提供=预输入NG变化=updateTypeahead()/>
和我想更新数据源
属性时,该领域的用户输入。功能 updateTypeahead
正确触发,但我没有访问触发事件,除非我用 $('#SEARCHTEXT元素)
,这是jQuery的方式,而不是AngularJS方式
什么是让AngularJS与旧式JS模块工作的最佳方式。
updateTypeahead(本)
不会DOM元素传递给函数 updateTypeahead(本)
。在这里,这个
将参考范围。如果您要访问的DOM元素使用 updateTypeahead($事件)
。在回调函数可以通过 event.target
获得DOM元素。
I use both Bootstrap and AngularJS in my web app. I'm having some difficulty getting the two to work together.
I have an element, which has the attribute data-provide="typeahead"
<input id="searchText" ng-model="searchText" type="text"
class="input-medium search-query" placeholder="title"
data-provide="typeahead" ng-change="updateTypeahead()" />
And I want to update the data-source
attribute when the user inputs in the field. The function updateTypeahead
is triggered correctly, but I don't have access to the element that triggered the event, unless I use $('#searchText')
, which is the jQuery way, not the AngularJS way.
What is the best way to get AngularJS to work with old style JS module.
updateTypeahead(this)
will not pass DOM element to the function updateTypeahead(this)
. Here this
will refer to the scope. If you want to access the DOM element use updateTypeahead($event)
. In the callback function you can get the DOM element by event.target
.
这篇关于在angularjs如何访问触发事件的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!