Compile template before projecting the content. Dynamic projecting?

痴心易碎 提交于 2019-12-24 07:13:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!