Is there any good solution when working with modals in a project where state is managed by NgRX?
The problem I have the following:
One of the solutions I see right now is to return multiple actions from the effect, one that adds created item to the store, second one to close the modal. For this I should include some modal identifier in "Create" action to identify which modal to close after "Create$" effect completes, but this will make effect more complicated.
I can't believe there is no ready solution to this problem.
I use ngx-bootstrap for modals.
UPDATE: Seems like to make this work I need to store (state + reducer + effects + actions) open/closed status for each modal available in the application. But anyway, no existing solution?
To close the modal, simply call the handleClose() function inside the onLoginFormSubmit() function body.
The NgRx Store is a Redux-inspired state management system that enables you to use observables to manage state in an Angular application. The primary advantage to using the NgRx Store is the ability to store all state in a single tree that is accessible from any part of the application.
NgRx implements the Flux-Pattern. At a high level, it helps you unify all events and derive a common state in your Angular app. With NgRx, you store a single state and use actions to express state changes. It is ideal for apps with many user interactions and multiple data sources.
NgRx is a framework for building reactive applications in Angular. NgRx is inspired by the Redux pattern - unifying the events in your application and deriving state using RxJS. At a high level, NgRx stores a single state and uses actions to express state changes.
I like to use an effect to handle the whole dialog flow, from opening the dialog to saving the entity and closing the dialog afterwards.
@Effect()
openDialog = this.actions.pipe(
ofType(LoginActionTypes.OpenLoginDialog),
exhaustMap(_ => {
let dialogRef = this.dialog.open(LoginDialog);
return dialogRef.afterClosed();
}),
map((result: any) => {
if (result === undefined) {
return new CloseDialog();
}
return new LoginDialogSuccess(result);
}),
);
See Start using ngrx/effects for this for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With