function injectThrottledCallback<TFn>(fn, options): (...args) => void;
Defined in: throttler/injectThrottledCallback.ts:39
An Angular function that creates a throttled version of a callback function. This function is essentially a wrapper around injectThrottler that provides a simplified API for basic throttling needs.
The throttled function will execute at most once within the specified wait time. If called multiple times within the wait period, only the first call (if leading is enabled) or the last call (if trailing is enabled) will execute.
This function provides a simpler API compared to injectThrottler, making it ideal for basic throttling needs. However, it does not expose the underlying Throttler instance.
For advanced usage requiring features like:
Consider using the injectThrottler function instead.
TFn extends AnyFunction
TFn
ThrottlerOptions<TFn>
(...args): void;
...Parameters<TFn>
void
// Throttle a scroll handler
const handleScroll = injectThrottledCallback((scrollY: number) => {
updateScrollPosition(scrollY);
}, {
wait: 100 // Execute at most once per 100ms
});
// Use in an event listener
window.addEventListener('scroll', () => {
handleScroll(window.scrollY);
});