filter
filter
operator filters values emitted by the source based on a provided predicate function.filter<T>(filterFn: (value: T) => boolean, options: SignalFilterOptions<T> = {}): T | null
Parameters
predicate | A predicate function that determines whether a signal should be emitted true or filtered out false . |
options | Optional. The combination of CreateEffectOptions and CreateSignalOptions (excluding the allowSignalWrites property) |
Example
Even Numbers
@Component({
template: `
<p>Interval: {{ intervalRef.interval() }} </p>
<p>Is even: {{ isEven() }} </p>
`
})
export class IntervalComponent {
intervalRef = createInterval(0, 1000);
private isEven = this.signalPipe(this.intervalRef.interval(), filter((count) => count % 2 === 0);
}