我想在我的视图中动态加载组件,这就是我试过的
在我的html文件中
<p>
<dynamic-component [componentData]="componentData"></dynamic-component>
</p>
然后在我的ts文件中我有
export class ChatCmpComponent implements OnInit {
private componentData = null;
ngOnInit() {
this.componentData = {
component: ChatInitButtonComponent,
};
}
现在收到错误
Can't bind to 'componentData' since it isn't a known property of 'dynamic-
component'.
1. If 'dynamic-component' is an Angular component and it has
'componentData' input, then verify that it is part of this module.
什么可能是错的,我如何动态加载组件
答案 0 :(得分:0)
您需要使用ng-template
并创建一个自定义指令,该指令允许您通过对ViewContainerRef
有关更多信息和示例,请尝试此处: