Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
How to detect which directive element was clicked from the controller?

I have an html template including an angularJS directive

<div my-users="users" ng-click="onUserClick()"></div>

the directive renders 2 elements, for example

[... code from the directive]
template:
'<div><input type="text" class="text1"><input type="text" class="text2"></div>'

I need to know, inside the controller, which of the input fileds in the directive was clicked

$scope.onUserClick = function() {
// what should I put here?
}

is it possible?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can detect what element was clicked using the $event parameter. This gives you a jQuery EventObject that you can inspect the element clicked using $event.target. But this will not be linked to the directive. If you want to tie click behaviors from the directive and expose that behavior to the parent controller, you should be using callbacks passed to directive behaviors (scroll down the the part using the &)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!