【发布时间】:2020-04-03 19:06:36
【问题描述】:
我正在尝试让组件 1 触发组件 2 中的功能,但组件 2 需要保持通用,以便任何组件都可以访问它。在不使其通用的情况下,我的代码如下所示:
组件1:
@Output() component2function = new EventEmitter<any>();
...
this.component2function.emit({ param1, param2 });
component2 选择器:
<component1 (component2function)="component2function($event)"> </component1>
这应该会触发component2function,但现在我想在不显式使用component1 选择器的情况下触发相同的功能,以便component2function 可以由component1 以外的组件触发。我该怎么做?
【问题讨论】:
-
你为什么不使用服务?
标签: angular typescript events components selector