ng-state
  • Introduction
  • Main differences
  • Getting Started
    • Instalation
    • Examples
  • Core concepts
    • Main idea
      • More complex flow visualization
    • Configuration
      • Immer Setup
      • ImmutableJs Setup
    • Store
      • Operators
      • Optimistic updates plugin
      • Optimistic updates plugin
      • Form manager plugin
        • onChange hook
        • shouldUpdateState hook
        • Custom form elements
      • Persist state plugin
        • Configuring custom storage
    • Actions
      • Immer
      • ImmutaleJs
      • Injectable Actions
    • Components with Actions
      • Signal Actions
      • State Actions
    • @InjectStore decorator
    • @WithStore decorator
    • @ComponentState decorator
    • Dispatcher
  • Different scenarios
    • Passing list item index via router
    • ngOnChanges hook
    • FormManager pitfalls
  • Unit testing
    • Setup
    • Test store
    • Test actions
    • Test component with actions
    • Test with Angular TestBed
  • Debugging
    • Setup
    • Redux DevTools
    • Automated changes output
    • Manual state changes check
    • Additional debugging information
  • Production
    • Production mode
    • Server Side Rendering (SSR)
  • Other information
    • Best practices
    • CLI
      • Custom Configurations
    • Performance
    • Blog Posts
    • Contributing
Powered by GitBook
On this page

Was this helpful?

  1. Core concepts
  2. Store

Form manager plugin

PreviousOptimistic updates pluginNextonChange hook

Last updated 6 years ago

Was this helpful?

This plugin simplifies working with 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:

  • debounceTime - time to wait until changes are synced. Default: 100ms

  • emitEvent - Angular pathValue parameter. Default: false.

Demo

https://angular.io/guide/reactive-forms
https://angular.io/api/forms/FormControl