Answer the question
In order to leave comments, you need to log in
Dynamyc Component for Angular 2. How to create dynamic components and templates?
In the process of learning Angular2, a question arose about dynamically adding teamlets that I receive from the server to the component. As far as I understand, Angular offers to dynamically create the components themselves for this. I didn't find anything in Russian. There is a rather interesting article in English , in which everything is not clear to me yet. I would be happy to talk with a knowledgeable person who can bring understanding)
If someone has come across a similar one, your opinion is interesting. I would like to put everything on the shelves in this matter.
Answer the question
In order to leave comments, you need to log in
Just did this this week. Everything is simple there, in fact:
1. Create a component with the desired template and a module for it.
2. With the help of RuntimeCompiler we compile the module and the component.
3. We find our ComponentFactory in the compilation results (theoretically, there can be many components in one module - therefore, a search is needed).
4. In the place we need, we get the ViewContainerRef and create an instance of the component in it using the ComponentFactory from paragraph 3.
5 The created component can be initialized. For example, set input parameters to it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question