Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to differentiate when an Angular component is loaded via template or a route?

Tags:

angular

Is there a way to tell how a component was loaded by Angular - I have a component that can be accessed via a route or loaded via another component's template and I'd like to be able to detect how the component was loaded for animation purposes.

like image 469
Neoheurist Avatar asked Oct 27 '25 05:10

Neoheurist


1 Answers

I'll give you two tricks one them either work use an input to your component and if it is loaded via selector you will get the input but not via router.

Second option is pass the data to component via data property in router and extract that in component constructor you got it means component is loaded from route else not.

If you've problem with router data then you have only option to detect route and aplly your logic

For router data resolving look into this https://www.google.ca/amp/s/yakovfain.com/2015/11/11/angular-2-passing-data-to-routes/amp/

like image 161
Babar Bilal Avatar answered Oct 29 '25 20:10

Babar Bilal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!