我正在尝试将数据绑定到一个角度为4的ng容器。
组件加载很好,但是当我添加[componentdata]=“testing”时,我得到错误
<ng-container *ngComponentOutlet="components.name" [componentData]="testing">
</ng-container>
误差
Error: Template parse errors:
Can't bind to 'componentData' since it isn't a known property of 'ng-container'.
1. If 'componentData' is an Angular directive, then add 'CommonModule' to the '@NgModule.imports' of this component.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("'Textarea' ">
<ng-container *ngComponentOutlet="widget.widgetComponent.component" [ERROR ->][componentData]="testing">
</ng-container>
</div>
你真的不能将数据绑定到ngcomponentoutlet吗?
最佳答案
要解决此问题,可以创建自定义组件
'custom-ng-container'
@Input() componentName : any;
@Input() componentData : any[];
HTML看起来像
<ng-container *ngComponentOutlet="componentName" >
</ng-container>
您应该在父组件中使用
<custom-ng-container [componentName]="components.name" [componentData]="testing"> </custom-ng-container>
关于angular - Angular 4:ngComponentOutlet-数据绑定(bind),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44220466/