1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

NgRX Store - init with Login (or Logout)

Discussão em 'Angular' iniciado por LeO, Setembro 30, 2024.

  1. LeO

    LeO Guest

    I can define my NgRxSignalStore with something like

    export const MyStore = signalStore(
    { providedIn: 'root' },
    withState(initialValues4Store),
    withMySignalState(),
    ....



    export function withMySignalState() {
    return signalStoreFeature(
    withState(additionalStates),


    which is fine when I want to have the store application wide - just one instance.

    What I'm not clear how to achieve a clear reset to the "initalValues" when the user logs out (or logs in). I know that I can create a method logout in MyStore and reset the values. Nevertheless the problem remains that I need to reset the values as well for the signalStoreFeature

    Is there a way to inject an instance globally AND run an Injector manually which creates a new instance after the user has logged out?

    EDIT

    Just as a sidenote: I've tried as well something like

    constructor(injector:Injector){...}
    doLogout(): {
    injector.get(MyStore);
    }


    But this did NOT reinitalize the store.

    Continue reading...

Compartilhe esta Página