I need to close angular material dialog from @ngrx/effect
here is my code
import { MatDialogRef, MatDialog } from "@angular/material/dialog";
import { AddComponent } from "./../../add/add.component";
@Injectable()
export class UserEffects {
@Effect()
addNewUser$ = this.actions$.pipe(
ofType(actions.UserActionTypes.addNewUser),
mergeMap((user: actions.addNewUser) =>
this.userService.createUser(user.user).pipe(
map(() => {
new actions.LoadUsers(),
this.notificationService.success("User added successfully!");
this.dialogRef.close(); <------ // here i try to close
}),
catchError(error => of(new actions.Error(error.error)))
)
)
);
constructor(
private actions$: Actions<actions.UserActions>,
private userService: UserService,
private notificationService: NotificationPopUpServiceService,
public dialogRef: MatDialogRef<AddComponent>
) {}
}
And with this i get error
main.ts:13 NullInjectorError: R3InjectorError[EffectsRootModule -> InjectionToken ngrx/effects: Root Effects -> UserEffects -> MatDialogRef -> MatDialogRef -> MatDialogRef]: NullInjectorError: No provider for MatDialogRef!
What is the best way to close material-dialog from effect or from service? Because we always need to set a name for the dialog component?
Thank you
I think the best solution to closing dialog is subscribing to the effect variable ie
// close the dialog
// Inside the dialog component
this.userEffects.addNewUser$.pipe(
ofType(Actions.LoadUsers)
).subscribe(_ => this.matDialogRef.close());
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