Type

AsyncDerivationFunction

@ng-forge/dynamic-forms

Async function for derivations — returns any value.

The function receives the evaluation context and may return a Promise or Observable. Register functions in customFnConfig.asyncDerivations.

Signature

type AsyncDerivationFunction<TFormValue extends Record<string, unknown> = any> = (
  context: EvaluationContext<unknown, TFormValue>,
) => Promise<unknown> | Observable<unknown>;

Type Parameters

NameConstraintDefaultDescription
TFormValueRecord<string, unknown>any-

Examples

const fetchPrice: AsyncDerivationFunction = async (context) => {
  const response = await fetch(`/api/price?product=${context.formValue.productId}`);
  const data = await response.json();
  return data.price;
};