I'd like to use NGXS to open modal which will set column visibility for datatable.
Here is my code:
state.ts file:
@Action(OpenColumnModal)
openColumnModal(ctx: StateContext<FeedStateModel>) {
const state = ctx.getState();
const allCols = state.allColumns;
return this.modalService.openColumnVisibilityModal(allCols).pipe(tap((result) => {
ctx.setState({
...state,
allColumns: result,
userColumns: result.filter(col => col.visible)
});
})
}
modal.service.ts:
openColumnVisibilityModal(columns): Observable<any> {
const dialogRef = this.dialog.open(ColumnVisibilityModal, {
data: columns,
autoFocus: false,
hasBackdrop: true,
disableClose: true
});
return dialogRef.afterClosed();
}
When I'm using modal opened by NGXS, after closing the state event isn't emitted. After that, I need to click somewhere to call the callback function inside openColumnModal function.
I'm using Angular Material dialog.
Does anyone know how to call callback function automatically after closing modal?
Thanks in advance:)