问题
In my project I am meeting several times the same problem, and yet, I have not been able to find a proper solution. I suspect it is all part of this issue, but it sounds to me like a very normal use case.
Many times I have a component with a template such as: <my-component><ng-content></ng-content></my-component>
where somewhere in the projected content is trying to get the instance of <my-component>
. This simply does not work because the projected component gets resolved before <my-component>
is compiled.
This makes impossible things like having custom form components while applying NgForm into them. Like I illustrate in this plunkr. Which sounds pretty standard to me.
Is there anyway to workaround this, without having to explicitly apply my-component
in the parent component?
来源:https://stackoverflow.com/questions/39557919/compile-template-before-projecting-the-content-dynamic-projecting