How to trigger function in other page?


#1

Hello guys,

I have two pages A and B which are not components.
How can I trigger a function in page B from A?
I know ViewChild can trigger function in components but I found it doesn’t work in this case…

Thanks,


#2

See:


#3

Thanks,

I understand EventEmitter is for child to parent interaction and Input is for parent to child component interaction.
Alternatively ViewChild can be used for parent to child interaction…
But I still don’t know what’s the best practice for page to page interaction?
How can I effortlessly trigger function in page B from page A?


#4

You probably shouldn’t, and it may suggest that your app needs to be restructured a bit. If you imagine your application as a tree of components, then pages are just components on that tree that sit on different branches, whereas parent/child components where communication is possible would sit on the same branch.

Pages shouldn’t communicate directly with each other. Generally, you would use a provider/service to facilitate whatever it is you are trying to do. The function should live in a service instead of a specific page if it needs to be called from other pages.