Difference between EventEmitter.next() and EventEmitter.emit() in Angular 2

Holger Stitz picture Holger Stitz · Mar 7, 2016 · Viewed 19.7k times · Source

What is the difference between EventEmitter.emit() and EventEmitter.next()? Both dispatching the event to the subscribed listeners.

export class MyService {
  @Output() someEvent$: EventEmitter<any> = new EventEmitter();

  someFunc() {
   this.someEvent$.emit({myObj: true});

   this.someEvent$.next({myObj: true});
  }
}

The documenation for the EventEmitter is not so helpful at the moment.

Answer

G&#252;nter Z&#246;chbauer picture Günter Zöchbauer · Mar 7, 2016

They do the same. emit() is the current version, next() is deprecated.

See also https://github.com/angular/angular/blob/b5b6ece65a96f5b8f134ad4899b56bf84afe3ba0/modules/angular2/src/facade/async.dart#L49