CngxFilter
projects/common/data/filter/filter.directive.ts
Import#
import { CngxFilter } from '@cngx/common/data'
Description#
Atom directive that holds one or more named filter predicates.
Supports both uncontrolled (internal state) and controlled modes.
In controlled mode the cngxFilter input takes precedence over the internal
'default' predicate - pair with filterChange to keep it in sync.
Multi-filter - use addPredicate(key, fn) / removePredicate(key) to
maintain a named stack of predicates. All active predicates are AND-combined
across keys: an item must pass every registered predicate to appear in results.
AND vs OR - the directive enforces AND across dimensions (keys). OR logic within a single dimension stays inside the predicate function itself:
// AND across dimensions: location AND role must both match
filter.addPredicate('location', p => selectedLocations.has(p.location));
filter.addPredicate('role', p => selectedRoles.has(p.role));
// OR within a dimension: London OR Rome - just put a Set inside one predicate
filter.addPredicate('location', p => selectedLocations.has(p.location));setPredicate / clear operate on the 'default' key and remain fully
backward-compatible with single-predicate usage.
Consumer connects this to a list via a computed() - nothing is injected
automatically.
Metadata#
Index#
Properties
Outputs
Derived State
Outputs#
Map boolean> Emitted whenever any named predicate is added or removed.
Instance Properties#
unknownEmitted whenever the 'default' predicate changes (backward-compat single-filter output).
output<((value: T) => boolean) | null>()unknownControlled predicate. When bound, takes precedence over the 'default' internal predicate.
input<((value: T) => boolean) | null>(null, { alias: 'cngxFilter' })unknownAll active named predicates.
Use addPredicate / removePredicate to manage this map.
this.predicatesState.asReadonly()Methods#
addPredicate(key: string, fn: function)Adds or replaces the named predicate key.
Emits predicatesChange with the updated map.
removePredicate(key: string)Removes the named predicate key (no-op if not present).
Emits predicatesChange with the updated map.