Form manager plugin

This plugin simplifies working with Reactive Forms: https://angular.io/guide/reactive-forms It keeps in sync state and form values. To do this you need to access store either from actions either injected to component and do following:

const form = this.store.select(['my-form-state-path']).form.bind(myForm)

where you myForm looks like:

this.myForm = new FormGroup({
    condition: new FormGroup({
        new: new FormControl(false),
        used: new FormControl(false),
        notSpecified: new FormControl(false)
    }),
    location: new FormControl()
});

from now on all changes made in state will be reflected in form and visa-versa.

Form plugin returns object with two methods:

  • Reset - resets form to initial state

  • Destroy - method that should be called from your ngOnDestroy method

As a second parameter of bind method some parameters can be passed:

Demo

Last updated