Angular reuse component in another position in dom WITHOUT reinitialization


In our Angular (v11) application, we use some components multiple times in different places in DOM, and they are toggled in/out with ngIf’s. Mostly because of reponsive design decisions. Example:

<comp1 ngIf*="mobile">

… and in another position, probably within some other components:

<comp1 ngIf*="desktop">

When we switch our view, the default Angular behaviour in this case is, the tag is removed from dom from the position1, the component will be killed, the tag is added in other position2 in dom, and the component will be reinitialized again.

Can we somehow without any component change, reuse this component in another position in DOM?

Source: Angular Questions

Categorized as angular Tagged


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us