onPropertyChange

This hook allows you to track property changes avoid boilerplate when using onChange hoock

constructor() {
const ngFormStateManager = this.actions.store.form
        .bind(this.form, { emitEvent: true, onChangePairwise: true })
        .onPropertyChange<MyState>(
            'quarterIncome',
            this.recalculateMonthlyIncome,
        )
        .onPropertyChange<MyState>(
            'monthlyIncome',
            this.recalculateQuarterIncome,
        );

    this.destroyRef.onDestroy(() => {
        this.actions.store.reset();
        ngFormStateManager.destroy();
    });
}

 private recalculateMonthlyIncome = (quarterIncome: number): void => {
    const monthlyIncome = quarterIncome ? parseFloat((quarterIncome / 3).toFixed(4)) : 0;
    this.actions.updateMonthIncome(monthlyIncome);
};

Last updated

Was this helpful?