是否可以通过NgTemplateOutlet订阅更改?

时间:2018-06-12 20:47:56

标签: angular angular6 eventemitter ng-template ng-container

我有一个Angular组件(ParentComponent),它接受并显示一个自定义的NgTemplate。我希望ParentComponent通过EventEmitter从NgTemplate中的组件接收事件。像这样:

ParentComponent.html

<!-- I want onCustomEvent to be called -->
<ng-container *ngTemplateOutlet="childTemplate" (customEvent)='onCustomEvent($event)'>
</ng-container>

OtherComponent.html

<ng-template #child>
  <button (click)='customEvent.emit("Hello World")'>Emit</button>
</ng-template>
<parent-component [childTemplate]='child'></parent-component>

这是我能想到的一个简单的例子,所以希望它足以说明问题。这样的事情可能吗?如果没有,可以用什么策略来完成同样的事情?

0 个答案:

没有答案