Reputation: 3484
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.
Upvotes: 4
Views: 86
Reputation: 2905
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/
Upvotes: 2