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
  3. Form manager plugin

onChange hook

This hook might be used for many use cases. One of them to update the view after state was changed if you are not using:

  • actions

  • async pipes

for example:

Selected location: {{ location }}
location: any;

constructor(private store: Store<any>, private cd: ChangeDetectorRef) { }

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

    this.store.select(['form', 'location']).subscribe(state => this.location = state);

    this.ngFormStateManager = this.store.select(['form'])
        .form.bind(this.filters)
        .shouldUpdateState((params: ShoulUpdateStateParams) => true)
        .onChange(state => this.cd.markForCheck());
}

This event will not be triggered if you are updating form state from the code manually

PreviousForm manager pluginNextshouldUpdateState hook

Last updated 5 years ago

Was this helpful?