Angular 将多个ng模板传递给子组件
父组件:Angular 将多个ng模板传递给子组件,angular,Angular,父组件: <child-component> <ng-template optionItem>Option item 1</ng-template> <---- want to send this template to child <ng-template optionItem>Option item 2</ng-template> <---- want to send this template to
<child-component>
<ng-template optionItem>Option item 1</ng-template> <---- want to send this template to child
<ng-template optionItem>Option item 2</ng-template> <---- want to send this template to child
... // more ng-template here //
</child-component>
<thirdparty-package>
<ng-content></ng-content>
</thirdparty-package>
但似乎ng内容
为空,无法找到这些模板
// but what i get is this
<thirdparty-package>
// missing ng-templates //
</thirdparty-package>
感谢您的帮助……也许您正在搜索Smething,就像我几周前回答的那样:Hi@Messervill我可能不需要动态加载组件。我需要将ng模板传递给孩子以便孩子加载。但是ng模板似乎在通往子组件的路上丢失了。嗨@Danaley,你解决了这个问题吗?因为我正在尝试同样的方法,但没有成功。嗨@LogixMaster,没有,我没有继续这个方法。相反,我的第三方软件包支持
exportAs
属性,因此我可以获得它的指令。所以,问题就解决了。
// but what i get is this
<thirdparty-package>
// missing ng-templates //
</thirdparty-package>
<child-component [myTemplate]="myTemplate"></child-component>
<ng-container #myTemplate>
<ng-template optionItem>Item A</ng-template>
<ng-template optionItem>Item B</ng-template>
</ng-container>