signalChange
Generic types: | T |
Used to run an effect when a signal reference changes. For example can be useful for running an effect when an input signal changes to replace the ngOnChanges lifecycle hook. The effect function will be called with the current value of the signal and the previous value.
Presentation
function signalChange (
signalRef: Signal <T> | InputSignal <T> | InputSignalWithTransform <T, unknown>,
effectFn: (current: T, previous: T | undefined) => void,
options?: { onCleanupFn?: (() => void) | undefined } | undefined,
): EffectRef ;
Returns
Parameters
Name | Type | Description |
---|---|---|
signalRef |
| @param signalRef The signal to be depend on |
effectFn | (current: T, previous: T | undefined) => void | @param effectFn The function to be called when the signal changes |
options | { onCleanupFn?: (() => void) | undefined; } | undefined | @param options Options for the effect
|
Example usage
myInputSignal = input ('initial value');
signalChange (myInputSignal, (current, previous) => { console.log('myInputSignal changed', current, previous); });