This article is a mirror article of machine translation, please click here to jump to the original article.

View: 1385|Reply: 3

[Angular] The Angular 18 series (twenty-six) implements lazy search capabilities based on RXJS

[Copy link]
Posted on 10/28/2024 5:18:59 PM | | | |
Requirements: When the text changes, the back-end interface should be called to query the keywords and return data, but often the user has not fully entered the keywords, and the text change event will be triggered many times, which will cause pressure on the back-end interface to frequently request, and there is also a certain pressure on the front-end frequent rendering. How to implement the delayed search function? That is, when the user enters the keyword completely, the backend interface query is called.

To facilitate the presentation, here is the settingDelay by one second, the renderings are as follows:



HTML page code:

The TS component code is as follows:

(End)





Previous:Docker MSSQL 2022 installs the full-text search service
Next:Practical combat: Linux uses firewall-cmd to manage firewalls
 Landlord| Posted on 5/15/2025 8:44:41 AM |
debounceTime() pipeline
The debounceTime pipeline is a built-in pipeline in Angular that can be used to debounce events. To use the debounceTime pipeline, you need to pass the debounce time (in milliseconds) as a parameter
distinctUntilChanged()
distinctUntilChanged is an operator that filters out the same values that are fired consecutively in an Observable. This is useful in situations where you want to prevent the Observable from firing the same value multiple times in a row.
 Landlord| Posted on 5/15/2025 9:29:33 AM |
AsyncValidatorFn validates latency stabilization

Reference:The hyperlink login is visible.
 Landlord| Posted on 5/15/2025 9:33:52 AM |
Little slag Posted on 2025-5-15 09:29
AsyncValidatorFn validates latency stabilization

Reference: https://stackoverflow.com/questions/36919011/how-to-add-debounc ...

Further encapsulation (Not tested

Example 1:

Example 2:
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com