angular
angular copied to clipboard
Add observed property to OutputEmitterRef
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
With the @Output
decorator, I used to check the observed
of the EventEmitter
(because it inherits Subject
) to enable/disable some features.
For example, <lu-select (clueChange)="..." />
would display a search bar in LuSelect
component but <lu-select />
would not.
This solution seems elegant as it avoid an additional input that would lead to unwanted cases:
- Both
<lu-select enableClue (clueChange)="..." />
and<lu-select />
would work -
<lu-select (clueChange)="..." />
would be useless because the search bar is not disabled becauseenableClue = false
-
<lu-select enableClue />
would be useless because the search bar is displayed, but nobody listen to its value
Proposed solution
Add a getter
property observed
in OutputEmitterRef
export class OutputEmitterRef<T> implements OutputRef<T> {
private listeners: Array<(value: T) => void>|null = null;
get observed(): boolean {
return !!this.listeners?.length;
}
//...
}
Alternatives considered
Replace existing usages of emitter.observed
by inputs.