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. Different scenarios

Passing list item index via router

When list item information should be on different page

There can be situation when list item is on page and its details on another. So question is how to deal with stateIndex. For this case you can pass list item index along with url params

<a href="#" [routerLink]="['/dictionaries', i]" class="card-link">Go To Values</a>

and on target component catch it and assign to stateIndex

constructor(private route: ActivatedRoute, private router: Router) {
    super();
    this.route.params.subscribe((params: Params) => {
      this.stateIndex = params.id;
    });
  }

and it will be passed to actions automatically.

Or with signal actions:

constructor(private route: ActivatedRoute, private router: Router) {
}
  

ngOnInit(): void {
    this.route.params.subscribe((params: Params) => {
      this.actions = signalActions(TodoStateActions, { 
        statePath: this.statePath, 
        stateIndex: params.id 
      });
    });
}
PreviousDispatcherNextngOnChanges hook

Last updated 8 months ago

Was this helpful?