2

I am going to add a dynamic component to the Angular template. Usually, it is done by creating a dynamic component via the existing ViewContainerRef in the template. But what about the situation where there is no ability to define manually? Is there some ability to put the view container to DOM programmatically? Like it can be done for other types of DOM Nodes via Renderer2's createElement method.

I tried to add ng-container via Renderer2, but it behaves as DOM element, not as view container ref.

2
  • A completely unplanned dynamic component is (so far as I know) not possible. But if you tell us our problem we can find a reason eventually. Commented Feb 18, 2023 at 11:28
  • You’d need to attach your component to something in the end I guess? Maybe have a look at angular material cdk - you could use a portal if that suits your requirements. Commented Feb 18, 2023 at 12:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.