Skip to main content

debouncedSignal()

The debouncedSignal function creates a debounced signal that updates its value after a specified timeout.

Parameters

ParameterTypeDefaultDescription
inputSignal<T>N/AThe input signal whose value will be debounced.
timeOutMsnumber0The debounce timeout in milliseconds. Defaults to 0.

Returns

TypeDescription
Signal<T>A new signal that updates its value after the specified debounce timeout.

Basic Usages

Signal

import { Component, signal, effect } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { debouncedSignal } from 'atomic-angular/utils';

@Component({
selector: 'app-debounced-example',
imports: [FormsModule],
template: `
<input [ngModel]="input()" (ngModelChange)="input.set($event)" />
<p>Debounced value: {{ debounced() }}</p>
`,
})
export class DebouncedExampleComponent {
input = signal('');
debounced = debouncedSignal(this.input, 1000);

constructor() {
effect(() => {
console.log(this.debounced());
// Logs the debounced input value after 1 second of inactivity.
});
}
}

Model Signal

import { Component, signal, effect } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { debouncedSignal } from 'atomic-angular/utils';

@Component({
selector: 'app-debounced-example',
imports: [FormsModule],
template: `
<input [(ngModel)]="input" />
<p>Debounced value: {{ debounced() }}</p>
`,
})
export class DebouncedExampleComponent {
input = model('');
debounced = debouncedSignal(this.input, 1000);

constructor() {
effect(() => {
console.log(this.debounced());
// Logs the debounced input value after 1 second of inactivity.
});
}
}