【问题标题】:Angular 4: ngComponentOutlet - data bindingAngular 4:ngComponentOutlet - 数据绑定
【发布时间】:2017-10-28 11:06:24
【问题描述】:

我正在尝试将数据绑定到 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>

真的不能绑定数据到ngComponentOutlet吗?

【问题讨论】:

标签: angular data-binding


【解决方案1】:

要解决此问题,您可以创建自定义组件

'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>

【讨论】:

  • 所以答案是你不能:(
  • 是的。你有使用*ngContainer的限制
  • 你能更新你的答案吗?这是不可能的
  • @Aravind 我需要在加载的组件页面中读取 componentData 值,而不是在“custom-ng-container”自定义组件中。例如: 组件:[{name:Page.component}]
猜你喜欢
  • 2018-03-04
  • 2017-12-05
  • 1970-01-01
  • 2017-10-20
  • 1970-01-01
  • 2017-08-27
  • 1970-01-01
  • 2019-01-01
  • 1970-01-01
相关资源
最近更新 更多