export declare class EventEmitter<T> extends Subject<T> { /** * Creates an instance of [EventEmitter], which depending on [isAsync], * delivers events synchronously or asynchronously. */ constructor(isAsync?: boolean); emit(value: T): void; /** * @deprecated - use .emit(value) instead */ next(value: any): void; subscribe(generatorOrNext?: any, error?: any, complete?: any): any; }
In Official Angular 2 Typescript definition, seems it has no way to mute or unsubscribe from EventEmitter.
I got callback over time as pages use the same EventEmitter
Since You are not using child to parent component iteration for fetching data from API there is no need to unsubscribe.
subscribe() is an EventEmitter method that registers handlers for events emitted by this instance. subscribe() have three optional parameters which can be used to pass values, errors, or completion notification in EventEmitter . The next parameter is a custom handler for emitted events.
You always have to unsubscribe from: Any Observable or Subject you created manually.
For passing the parameters, we will wrap all the parameters inside the curly brackets (this will combine them as a single object) and pass it to the emit method. To receive the parameters in the parent component, we will make a similar type of object and update its value with that of the received object.
EventEmitter extends Subject. When you subscribe to a subject you get a Subscription
which you can later use to unsubscribe.
someOutput:EventEmitter = new EventEmitter(); ... this.subscription = someOutput.subscribe(...); ... this.subscription.unsubscribe();
Hint
Don't use EventEmitter
for anything else but @Output()
s. Angular doesn't guarantee that EventEmitter
will keep extending Subject
or even work similar to a Subject
in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With