davidshen84 davidshen84 - 1 year ago 94
Javascript Question

in angularjs how to access the element that triggered the event?

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


<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
attribute when the user inputs in the field. The function
is triggered correctly, but I don't have access to the element that triggered the event, unless I use
, which is the jQuery way, not the AngularJS way.

What is the best way to get AngularJS to work with old style JS module.

Answer Source

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.

Blockquote Please Note : ng-change function doesn't allow to pass $event as variable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download