A
A
Alex102142021-06-06 16:43:45
Angular
Alex10214, 2021-06-06 16:43:45

How to call a function from one component in another?

Hello, I have a modal. It consists of a separate component. It has a couple of buttons. And I need to call a function from another component when clicking on a specific button in a modal. Please tell me how to do it? or maybe an example? I know that you can use BehaviorSubject to pass data between components, but I don't know how to call the function. Can someone explain, if not difficult. And is it correct to call the functions of other components through subjects at all ??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Kadyrov, 2021-11-01
@Ahmad66617

If you use NgRx, then it’s very simple - you dispatch the event and actually catch it in the effect, but before the state management - I did it simply (unless of course there are 100500 modals there) - in the Output through the EventEmitter you issue a flag or an object, or the same stream in RxJs - and you check it at the output - the flag has changed - called one method, if not - then for example another, but it's better to display it through the states - if the application becomes overgrown with modals and other embellishments - you will get confused quickly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question