6

There is a EventEmitter:

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

How to check if anyone is subscribed to EventEmitter in Angular?

Tom Smykowski
  • 25,487
  • 54
  • 159
  • 236
  • 1
    You can't. That's not how observables work. Please share what the original problem was that gave you this idea as the solution. – Reactgular Aug 13 '19 at 13:28

1 Answers1

4

Angular EventEmitter is an RXJS Subject:

class EventEmitter<T> extends Subject

Therefore you can use the currentObservers 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.
 */
export class Subject<T> extends Observable<T> implements SubscriptionLike {
  closed = false;

  private currentObservers: Observer<T>[] | null = null;

Notes

  • RxJs API changed property name from observers to currentObservers
  • Rather than using an EventEmitter, consider BehaviorSubject or ReplaySubject.

See: Delegation: EventEmitter or Observable in Angular

Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117