【问题标题】:Angular: set @Output from codeAngular:从代码中设置@Output
【发布时间】:2018-01-18 18:32:23
【问题描述】:

我能否以某种方式从parent.component.ts 设置子组件的@Output() 属性,而不必在其HTML 文件中写入(something)="doSmething()"?我需要这个用于动态组件。

也许ContentChildrenViewChildrenViewContainerRefEmbeddedViewRef 带有选择器?

【问题讨论】:

  • 你能用更多信息解释你的问题吗

标签: angular


【解决方案1】:

类似的东西?

createChild() {
    const factory = this.resolver.resolveComponentFactory(ChildComponent);
    const ref = this.location.createComponent(factory);
    ref.something.subscribe(event => this.doSmething());
    ref.changeDetectorRef.detectChanges();
    return ref;
}

【讨论】:

  • 我正在使用这样的东西:row.createEmbeddedView(cell.template, {$implicit: someData});,其中rowViewChildcellDirective
猜你喜欢
  • 1970-01-01
  • 2018-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-20
  • 1970-01-01
  • 2021-11-06
  • 2020-07-14
相关资源
最近更新 更多