我想將數據綁定到Angular 4中的ng-container。 組件加載罰款,但是當我添加[componentData] =「測試」我得到錯誤Angular 4:ngComponentOutlet - 數據綁定
<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?
你有' ng-container'用於'template'的情況。 '[componentData]'是一個自定義的@Input()'屬性,它不可用作輸入。 – Aravind
看看https://stackoverflow.com/questions/44281288/reflectiveinjector-is-not-instantiating-component-correctly-with-ngcomponentoutl下面是一個替代方案https://stackoverflow.com/questions/42522633/angular- 4-assign-input-for-ngcomponentoutlet-dynamic-created-component – yurzui