New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removal of compileComponentAsync in RC6 #11277
Comments
There are two possible solutions to your problem: 1/ if your components are not lazily loaded, then you should list all of your dynamic components in the
2/ if your components are lazily loaded, since you are doing a lot of dynamic work already, you might as well create the modules dynamically.
More background info: We can't bring the old behavior back because compiling individual components requires the compiler to know the context in which the component should be compiled. e.g. what directives and pipes should be considered when compiling the component's template. before we introduced (now removed) platform directives, it was possible to safely compile individual components because you had to specify all the imported directives and pipes via So while the more common use-case got much simpler, your case got more difficult because you now have to create modules for your components. I just don't see how we can satisfy both scenarios. |
Igor, Can you expand a bit on the second solution you propose where modules are created dynamically? I don't see any documentation on any kind of 'generateModule' method. Is this something that is currently supported in Angular 2 or are you suggesting it as a hypothetical method one might implement to get around the issue? I imagine the general idea would be to create a basic NgModule scaffolding around a component at runtime to enable dynamic compilation. Is this what you had in mind or have I misunderstood? Thanks |
I assume it's something like a component can be created dynamically as shown in #7596 (comment) |
@IgorMinar I've tried the following approach: how-can-i-use-create-dynamic-template-to-compile-component-with-angular2-rc6. And it seems to work ok, until I had a template that uses Now I had to provide the dynamically created The problem is that even if I click on a route, it only changes the URL, but the view does not get updated. Creating a plunk with this issue is not trivial. But I must ask, is there any easy way of having a component with a dynamic template? Or is there away to change the HTML of a template and recompile it or refresh it? I tried |
Hi Igor Sorry for the late answer. I was on holiday. I have played around with the new Settings you have proposed and could not get it to work: about 1/: if I run it tells me that there is no componentFactory associated with MyDynamicComponent. I couldn't find a way to write or generate such a factory. about 2/: where does generateModule come from? I also found no reference to anything like that. about my original way that I wanted to avoid: When I am trying to write a module for every Component I get it to work. This time I have to hand over the Module and the Component. Which is too much overhead.
|
Created a new Feature Request: |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a ... (check one with "x")
Current behavior
With RC6 the method compiler.compileComponentAsync(...) has been replaced with compiler.compileModuleAsync(...). That allows me to render Modules dynamically.
Problem is that if I want to render a single component, I would have to create a module class for each component that should be available dynamically.
Im not saying that rendering modules isn't a good thing. I would just prefer if it would also be possible to render components directly without the additional overhead.
Expected/desired behavior
Would it be possible to bring the old behaviour back?
Reproduction of the problem
what I am currently doing:
What is the expected behavior?
Make the rendering of components possible again without the overhead of writing a module for each component.
What is the motivation / use case for changing the behavior?
Im not saying that rendering modules isn't a good thing. I would just prefer if it would also be possible to render components directly without the additional overhead.
Please tell us about your environment:
The text was updated successfully, but these errors were encountered: