Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 7, Ngrx, Rxjs 6 - Accessing state between lazy loaded modules

I am using Angular 7 with Ngrx and Rxjs 6. I got 2 lazy loaded modules A and B which have their own selectors and reducers.

Now, I would like to access the data stored on the module B state from the module A. The problem is that all of the ngrx components of module B get initialized only when the user navigates to the lazy loaded route of B, so if the user first goes to A , attempting to select the state will result in undefined errors because B is not yet initialized.

What would be the best practice in accessing the state of a lazy loaded module in this case?

like image 935
qubits Avatar asked May 18 '19 14:05

qubits


1 Answers

In my opinion his use case is valid and ngrx ought to be able to handle it but it drops state if a reducer is not added to ngrx through the forFeature function because a lazy loaded module is not yet loaded which makes it impossible to retrieve the entire state from a database in the backend and use it as needed in lazy loaded modules.

like image 62
Robert Brower Avatar answered Oct 22 '22 01:10

Robert Brower