gpt4 book ai didi

angular - 如何检查是否有人订阅了 Angular 中的 EventEmitter?

转载 作者:行者123 更新时间:2023-12-03 23:51:16 25 4
gpt4 key购买 nike

有一个事件发射器:

@Output() edit: EventEmitter<any> = new EventEmitter();

如何检查是否有人订阅了 Angular 中的 EventEmitter?

最佳答案

Angular EventEmitter 是 RXJS Subject :

class EventEmitter<T> extends Subject
因此您可以调用 .observers属性(property)。
RXJS Source Code
/**
* A Subject is a special type of Observable that allows values to be
* multicasted to many Observers. Subjects are like EventEmitters.
*
* Every Subject is an Observable and an Observer. You can subscribe to a
* Subject, and you can call next to feed values as well as error and complete.
*
* @class Subject<T>
*/
export class Subject<T> extends Observable<T> implements SubscriptionLike {

[rxSubscriberSymbol]() {
return new SubjectSubscriber(this);
}

observers: Observer<T>[] = [];

备注 EventEmitter而不是使用 EventEmitter , 考虑 BehaviorSubjectReplaySubject .
见: Delegation: EventEmitter or Observable in Angular

关于angular - 如何检查是否有人订阅了 Angular 中的 EventEmitter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57478762/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com