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

后端 未结 2 741
借酒劲吻你
借酒劲吻你 2021-01-31 23:55

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



        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-01 00:40

    In the latest version(Ng9), the source code of event_emitter.ts goes as following:

    export class EventEmitter extends Subject {
      /**
       * Emits an event containing a given value.
       * @param value The value to emit.
       */
      emit(value?: T) { super.next(value); }
    }
    
    

    EventEmitter extends from parent class Subject. And emit method call super.next() as you may expected.

提交回复
热议问题