Hol*_*itz 81 angular2-services angular
EventEmitter.emit()和之间有什么区别EventEmitter.next()?两者都将事件分派给订阅的侦听器.
export class MyService {
@Output() someEvent$: EventEmitter<any> = new EventEmitter();
someFunc() {
this.someEvent$.emit({myObj: true});
this.someEvent$.next({myObj: true});
}
}
Run Code Online (Sandbox Code Playgroud)
在为EventEmitter documenation是此刻不那么有用.
在最新版本(Ng9)中,源代码event_emitter.ts如下:
export class EventEmitter<T extends any> extends Subject<T> {
/**
* Emits an event containing a given value.
* @param value The value to emit.
*/
emit(value?: T) { super.next(value); }
}
Run Code Online (Sandbox Code Playgroud)
EventEmitter从父类扩展Subject。和emit方法调用,super.next()如您所料。
| 归档时间: |
|
| 查看次数: |
15124 次 |
| 最近记录: |