Reusable logic in Angular apps

added by JavaScript Kicks
7/9/2019 7:12:58 AM


The easiest way to accomplish the goal (implement a live search) is to provide the necessary code within a component's class, namely: with a simple template: In the above example, the flow is the following: an input event is triggered, the input's value is pushed into the carsQuerySubject, the subjects acts as the source stream for the cars$ observable emitting a matching cars array, the cars$ stream is created with the aid of standard operators used for the live search case (debounceTime, distinctUntilChanged, switchMap).