1

I have a full template

I would like to put a watch on this tempalte, in order to call a function in the controller any time something is clicked inside that template.

I know I have to use a watch (I believe I do) but I don't understand how to to the connection between the full template and the watch.

1 Answer 1

2

To do this just add the ng-click directive to your parent element so that every click inside that element evaluates the expression inside the ng-click attribute:

<div class="parent" ng-click="callFunction()">
 <div>Hello World</div>
</div>

If you want some clicks inside the parent element to not trigger the parent ng-click you can add $event.stopPropagation() to stop event propagation:

<div class="parent" ng-click="callFunction()">
 <div>Clicking here will call parent callFunction()</div>
 <div ng-click="$event.stopPropagation();callAnotherFunction();">
  Clicking here won´t call parent´s callFunction()
 </div>
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.