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?
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 &)