本文介绍了Angular 2中的EventEmitter.next()和EventEmitter.emit()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EventEmitter.emit()EventEmitter.next()有什么区别?两者都将事件调度到订阅的侦听器.

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});
  }
}

EventEmitter的文档目前并不那么有用.

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

推荐答案

它们执行相同的操作. emit()是当前版本,next()已过时.

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

另请参见 https://github.com/angular/angular/blob/b5b6ece65a96f5b8f134ad4899b56bf84afe3ba0/modules/angular2/src/facade/async.dart#L49

这篇关于Angular 2中的EventEmitter.next()和EventEmitter.emit()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 07:32