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

时光总嘲笑我的痴心妄想 提交于 2019-12-31 10:05:28

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/35840576/difference-between-eventemitter-next-and-eventemitter-emit-in-angular-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!