父组件:
<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-templates传递给Child component
,以便第三方包组件可以像往常一样使用以下结构处理它。
// expected structure
<thirdparty-package>
<ng-template optionItem>Option item 1</ng-template>
<ng-template optionItem>Option item 2</ng-template>
// more ng-template here //
</thirdparty-package>
但似乎ng-content
为空,无法找到这些模板。
// but what i get is this
<thirdparty-package>
// missing ng-templates //
</thirdparty-package>
如何将多组ng-template
发送到子组件并放入<thirdparty-package></thirdparty-package>
内?
我尝试过@input和TemplateOutlet没有更好的结果
<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>
感谢您的帮助......