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
DynamicComponentLoader does not support inputs or outputs #6326
Comments
dup of #6223 ? |
Outputs are not supported as well, just tried it. |
Not sure about the output, but I was able to set my inputs using the promise:
this is assuming your component declares inputs this way:
|
I came to the same result as @xtiancapil. My code: this.dcl.loadIntoLocation(ComponentToLoad, this.elementRef, 'host')
.then((component) => {
component.instance.inputValue = "whatever";
component.instance.outputValue.subscribe((value) => {
// do smth
});
}); And I marked this code as temporal. Before I find better ideas. Hope so) |
There is a difference with the @input behavior: the dynamic component's template will be rendered once before properties are set, which leads to error in template rendering if we have a dot notation there. We don't make use of the @input() annotation, we just set the public properties later. I am using the previous notation as well, but looking forward to pass real inputs :) |
Not sure what your problem is.
this is also the case for other components where values are fetched from the server for example. Just use |
@zoechi Oh I didn't know this trick! Thanks a lot, it helps to avoid this issues. You are right, we may have the same issue with remote data. However, I would have expected it to be the default behavior with It pointed a difference with @input behavior when using |
That doesn't work with ngControl, e.g. |
Are there plans to fix this issue? |
I just ran across this while trying to do something similar to the OP. I have a list of blocks that I need to render into the view using a component based on the block.type, so I'm using the DynamicComponentLoader. For the blocks to work, I need to bind an @input to the block data. |
@tdterry GitHub issues are for bug reports. For support questions please use one of the channels mentioned in https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question |
The workaround of using the promise is not good for me. One of the @input in my case are "data" that comes from a service and that are not available when I create the component. The data will arrive later but seems that the new component is not aware about that change. For me is strategic that the @input and @output are supported by DynamicComponentLoader. Please fix it! |
Let's track this one as part of #8164 where we are going to have proper API / solution for interacting with inputs / outputs of dynamically loading components. Closing as a duplicate. |
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. |
If a child component requires an input (like the HeroDetailsComponent has, which is the selectedHero), it can't be loaded dynamically. There's no way to instantiate a child component with inputs this way.
The text was updated successfully, but these errors were encountered: