6

There is a EventEmitter:

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

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

Tom Smykowski
  • 24,566
  • 52
  • 155
  • 227
  • 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

3

Angular EventEmitter is an RXJS Subject:

class EventEmitter<T> extends Subject

Therefore you can call the .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>[] = [];

Note on EventEmitter

Rather than using an EventEmitter, consider BehaviorSubject or ReplaySubject.

See: Delegation: EventEmitter or Observable in Angular

Community
  • 1
  • 1
Christopher Peisert
  • 18,667
  • 3
  • 73
  • 100
  • 1
    I was using this technique but I have this "depreacation" warning: "Internal implementation detail, do not use directly. Will be made internal in v8." Anyone knows how to replace this ? – Tonio Feb 21 '22 at 11:04