My custom component click
function is triggered twice - both custom component's event and sample level event are triggered.
Here's my Plunker:
https://plnkr.co/edit/wp2iWh7OStdPm5uXsWbP?p=preview
Answers. Post the code of the object you are clicking on, and the event that is firing twice. Usually this is caused by declaring it in the OnClick event, as well as Handles Something.
Events are handled in Angular using the following special syntax. Bind the target event name within parentheses on the left of an equal sign, and event handler method or statement on the right. Above, (click) binds the button click event and onShow() statement calls the onShow() method of a component.
Because you have bound it twice on the child component and on the parent component. The mouseEvent
propagates from the child component to the parent component by default. You can stop propagation of event to parent component.
<div (click)="divClick($event)">Custom Div Clcik here!</div>
divClick(event) {
event.stopPropagation();
alert("divClick");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With