Angular 4 : ngComponentOutlet - data binding

标签 angular data-binding

我现在正在尝试将数据绑定(bind)到 Angular 4 中的 ng-container。 组件加载正常,但是当我添加 [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>

真的不能将数据绑定(bind)到 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 4 : ngComponentOutlet - data binding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44220466/

相关文章:

Angular 2 Multi-Tenancy 系统 - 用户名为 "subdomain"

c# - WPF 可能与 where 子句绑定(bind)?

Silverlight - 使用 MVVM 动态地将椭圆添加到 Canvas

Angular 8 : Cannot instantiate cyclic dependency - ActivatedRoute

javascript - 过滤管道总是记录未定义的

angular - 如何使用 DynamicComponentLoader 定位特定元素?

c# - XAML 索引器数据绑定(bind)

html - PrimeNg CSS 不工作

wpf - 使用 ObservableCollection 数据绑定(bind)从线程更新数据网格

c# - 使用多重绑定(bind)更新源