Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ng-click - background issue

I have little problem with ng-click.

My code is like this:

<div ng-click="changeVal()">
   content
   <span ng-click="changeColor()">content</span>
</div>

Of course now when I click span angular trigger two clicks (val and color). But I would like to trigger only one click (changeColor).

I can't add another element inside the div which will fill the whole div because the template I use won't allow this.

Is there a kind of method to trigger ng-click when I click on the div's background?

like image 606
buszito Avatar asked Aug 05 '26 07:08

buszito


2 Answers

You need to stop event from propagating. Update your code to following

<span ng-click="changeColor(); $event.stopPropagation();">content</span>
like image 124
Nikhil Aggarwal Avatar answered Aug 08 '26 09:08

Nikhil Aggarwal


I think you want to use $event.stopPropagation() in changeColor(). Pass $event to the function changeColor($event) OR just do changeColor();$event.stopPropagation();

like image 39
Arg0n Avatar answered Aug 08 '26 08:08

Arg0n



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!