DEV Community

KristijanFištrek
KristijanFištrek

Posted on

3

Angular (click) - multiple functions?

Scenario
-> on click of a button you need to check data from two functions with (click) attribute.

Do you :
A) create a third function which encapsulates the two & pass that in the (click).
Example : (click)="thirdFunction()"
B) you pass both of them.
Example :
(click)="first(); second();"

What seems to be the best practice for you?

Top comments (3)

Collapse
 
wescopeland profile image
Wes Copeland

I would go with Option A, call it on[Whatever]Click(). That way there is a single click handler for the output and you're less likely to have unintended side-effects.

Collapse
 
kristijanfistrek profile image
KristijanFištrek

Sounds nice!

Collapse
 
dhanush9952 profile image
Dhanush

option A will not work all the time

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay