0

How do I create a component from a variable name in Angular similar to what can be achieved in Vue using Dynamic Components:

<component :is="myTemplate.type"></component>

1 Answer 1

1

Before Ivy: You should use the ComponentFactoryResolver. You can check out a good example of it here: link

With Angular Ivy
You can use the renderComponent function. You can check out my blog about Ivy and dynamic component rendering here: link

Sign up to request clarification or add additional context in comments.

2 Comments

This answer would be more helpful if you included the code to do both ways in your answer.
We're still at Angular 7 so I went with the first option(key-value map of available component) and it seems to work.

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.