1

In Angular5,

I have the code like below.

   <div (click)="abc()">
    some content
    <button (click)="xyz()">Click</button>
    </div>

Whenever I click on button,the two methods are calling.But i want to call a single method.it belongs to button click.

How to handle it in Angular5

Thanks,

1 Answer 1

3

You need to stop the propagation of the event in the xyz method:

thus in the template :

<div (click)="abc()">
    some content
    <button (click)="xyz($event)">Click</button>
</div>

In the component

xyz = function (event: Event) {
    event.stopPropagation();
    ... // rest of the stuff 
}
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.