Art*_*ter 8 angular-material ngrx-effects angular ngrx-store
我需要从 @ngrx/effect 关闭角度材质对话框
这是我的代码
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>
) {}
}
Run Code Online (Sandbox Code Playgroud)
有了这个我得到了错误
main.ts:13 NullInjectorError: R3InjectorError[EffectsRootModule -> InjectionToken ngrx/effects: Root Effects -> UserEffects -> MatDialogRef -> MatDialogRef -> MatDialogRef]: NullInjectorError: 没有 MatDialogRef 的提供者!
从效果或服务中关闭材料对话的最佳方法是什么?因为我们总是需要给对话框组件设置一个名称?
谢谢
我想我找到了解决方案,但如果有更好的东西,请告诉我......我添加this.dialogRef.closeAll()
class UserEffects {
constructor(
private actions$: Actions,
private dialogRef: MatDialog,
private notificationService: NotificationService,
) {}
@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.closeAll(); <--- //this is the key
}),
catchError(error => of(new actions.Error(error.error)))
)
));
}
Run Code Online (Sandbox Code Playgroud)
编辑:
模态已关闭,但出现错误
core.js:6014 ERROR 错误:效果“UserEffects.addNewUser$”调度了无效操作:未定义
类型错误:操作必须是对象
有什么帮助吗?谢谢
| 归档时间: |
|
| 查看次数: |
3845 次 |
| 最近记录: |