Questions tagged [ngxs]

NGXS - Provides State Management for Angular apps based on a Event Sourcing model.

Questions about NGXS

The way we (the ngxs team) would prefer getting questions is on stackoverflow with the ngxs tag. And that we only post issues (bugs) to github.

By having questions on stackoverflow instead of the github issues, they don't get lost when we close the issue.

If you are unsure if your problem is bug or not, it's better to post it here on stackoverflow. The ngxs team monitors stackoverflow, and will try to answer your question as soon as possible, so you will have the same attention here.

You can also try joining our slack channel and ask your question there, but again I think it's better that we populate stackoverflow with the questions and answers as they are easily searchable and indexed by google.

541 questions
39
votes
2 answers

What is state management in angular? and why should I use it?

I am new to Angular and this question might be very broad. But I am interested in learning more on State management usage. Recently one of our project implemented state management using NGXS library. However I am trying to understand what are all…
ac184
  • 811
  • 2
  • 10
  • 19
38
votes
3 answers

Difference in performance between ngrx and ngxs?

I want to use ngxs for state management in my Angular 6 application. But I am not sure if it is mature for big projects. I can not find any articles about Difference in performance between ngrx and ngxs. Can someone provide some info about…
John Doe
  • 3,794
  • 9
  • 40
  • 72
24
votes
2 answers

Actions/state to load data from backend

I've just started experimenting with ngxs but from my reading so far I'm not 100% clear on where I should be calling back to my API to persist and read data (all examples I've seen are either not doing it, or using some mock). E.g. I've created a…
Garth Mason
  • 7,611
  • 3
  • 30
  • 39
22
votes
2 answers

How to use patchState vs setState in NGXS?

I am learning ngxs but I can't understand when should I use patchState and setState? What's the difference? const state = ctx.getState(); let data = this.service.list(); ctx.setState({ ...state, feedAnimals: data }); vs. let data = …
18
votes
3 answers

Pipe and Tap VS subscribe with ngxs

I am playing around with pipe and subscribe. If I am using pipe with tap, nothing will log in console. If I am using subscribe, it's working. So what I am doing wrong? import { Observable } from 'rxjs'; import { tap, take } from…
Paul
  • 2,430
  • 3
  • 15
  • 20
13
votes
3 answers

Should we unsubscribe from ngxs Selector?

I'm using ngxs State management. Do I need to unsubscribe from Selectors or is this handled by ngxs? @Select(list)list$!: Observable; this.list$.subscribe((data) => console.log(data));
Tamer Hussien
  • 717
  • 1
  • 9
  • 21
12
votes
3 answers

NGXS: How to test if an action was dispatched?

How to unit test whether an action was dispatched? For example, in a LogoutService, I have this simple method: logout(username: string) { store.dispatch([new ResetStateAction(), new LogoutAction(username)]); } I need to write a unit test…
Francesco Cina
  • 907
  • 1
  • 11
  • 19
11
votes
4 answers

How to mock @Select in ngxs when using a mock store

I am using ngxs for state handling in angular, and I am trying to test our components as units, so preferably only with mock stores, states etc. What we have in our component is something like: export class SelectPlatformComponent { …
Wouter
  • 3,976
  • 2
  • 31
  • 50
11
votes
1 answer

How to use selectSnapshot?

I have a guard that checks if there is a token on state. canActivate(): boolean { const token = this.store.selectSnapshot((state: AuthenticationState) => state.token); if (!token) { return true; } this.router.navigate(['home']); return…
Jonathan Lightbringer
  • 435
  • 2
  • 12
  • 27
9
votes
1 answer

Is it possible to share NGXS store between separate Angular (sub)projects?

The situation: I have a micro-frontend made of a host Angular app and many Angular libraries imported as modules containing components that behave as 'sub-apps'. The goal: I want to share the NGXS store created in the host app between all sub-apps,…
fusio
  • 3,595
  • 6
  • 33
  • 47
9
votes
1 answer

NGXS updateItem state operator

I'm trying to use the NGXS state operators inside of my application, but I'm having trouble finding good examples of how to use them for slightly more complex updates. For example, NGXS's documentation shows an example of updating this…
darkknightdetec
  • 101
  • 1
  • 3
9
votes
1 answer

Abstracting selectors and action handlers from state

I was wondering whether it's possible to abstract the @Selectors and/or the @Action handlers from the @State class to a separate file? As the state grows bigger and as the selectors more complex, I'd like to move them to a separate file to keep the…
Ale
  • 103
  • 6
8
votes
1 answer

Cannot find module 'src/app/services/session.response' or its corresponding type declarations

I have upload my project Angular on Stackblitz, the project works perfectly on Visual Studio Code. But, when I open the project on Stackblitz, I have an error message: Error in src/app/store/session/session.actions.ts (1:32) Cannot find module…
aagharaf
  • 103
  • 1
  • 6
8
votes
0 answers

Possible to genericize NGXS actions?

I'd like to write just one action to perform the same CRUD operations on state, just on different slices of it, while preserving type safety. For example, I'd like to use the following action to apply a set operation to any slice with a generic…
skwny
  • 2,930
  • 4
  • 25
  • 45
8
votes
1 answer

When do selectors execute? ngxs

live demo https://stackblitz.com/edit/angular-vw78jf There is ToppingsStateModel in my ngxs state export interface ToppingsStateModel { entities: { [ id: number ]: Topping }; selectedToppings: number[]; } One action change my entities list,…
Сергей
  • 226
  • 2
  • 9
1
2 3
36 37