Angular 从共享服务关闭“材质”对话框
在我的Angular 8应用程序中,我使用Angular 从共享服务关闭“材质”对话框,angular,Angular,在我的Angular 8应用程序中,我使用Angular material dialog执行CRUD操作。 如果我想关闭来自同一组件的组件中的对话框,我将该构造函数中的ref设置为对话框组件的名称 constructor( @Inject(MAT_DIALOG_DATA) public dialogRef: MatDialogRef<AssingTrialRoleComponent>, //AssingTrialRoleComponent name of class private
Angular material dialog
执行CRUD操作。
如果我想关闭来自同一组件的组件中的对话框,我将该构造函数中的ref设置为对话框组件的名称
constructor(
@Inject(MAT_DIALOG_DATA)
public dialogRef: MatDialogRef<AssingTrialRoleComponent>, //AssingTrialRoleComponent name of class
private store: Store<fromStore.State>
) {
如果触发了catchError
,则对话框需要保持打开状态,如果success
我需要从共享通知服务关闭对话框
这是我的通知服务
export class NotificationPopUpServiceService {
constructor(public snackBar: MatSnackBar) {}
config: MatSnackBarConfig = {
duration: 3000,
horizontalPosition: "right",
verticalPosition: "top"
};
success(msg) {
this.config["panelClass"] = ["notification", "success"];
this.snackBar.open(msg, "", this.config);
this.dialogRef.close(); <-- this is where I need to close dialog
}
warn(msg) {
this.config["panelClass"] = ["notification", "warn"];
this.snackBar.open(msg, "", this.config);
}
}
导出类NotificationPopupService服务{
构造函数(公共snackBar:matsnakbar){}
配置:MatsnakBarConfig={
时长:3000,
水平位置:“对”,
垂直位置:“顶部”
};
成功(味精){
this.config[“panelClass”]=“通知”,“成功”];
this.snackBar.open(msg,“,this.config);
可能每个组件中NotificationPopUpServiceService的DI by构造函数就是解决方案
在您的服务中:
export class NotificationPopUpServiceService {
constructor(public snackBar: MatSnackBar) {}
config: MatSnackBarConfig = {
duration: 3000,
horizontalPosition: "right",
verticalPosition: "top"
};
success(msg) {
this.config["panelClass"] = ["notification", "success"];
this.snackBar.open(msg, "", this.config);
this.closingDialogEvent('dialogName'); //is going to close the notification from a specific call
}
warn(msg) {
this.config["panelClass"] = ["notification", "warn"];
this.snackBar.open(msg, "", this.config);
}
closingDialogEvent(name:string) {
this.dialogRef.close(name);
console.log('event after closing dialog' );
}
}
也许每个组件中NotificationPopupService的DI by构造函数就是解决方案
在您的服务中:
export class NotificationPopUpServiceService {
constructor(public snackBar: MatSnackBar) {}
config: MatSnackBarConfig = {
duration: 3000,
horizontalPosition: "right",
verticalPosition: "top"
};
success(msg) {
this.config["panelClass"] = ["notification", "success"];
this.snackBar.open(msg, "", this.config);
this.closingDialogEvent('dialogName'); //is going to close the notification from a specific call
}
warn(msg) {
this.config["panelClass"] = ["notification", "warn"];
this.snackBar.open(msg, "", this.config);
}
closingDialogEvent(name:string) {
this.dialogRef.close(name);
console.log('event after closing dialog' );
}
}
在NotificationPopUpServiceService
中,在构造函数中,我们需要设置公共对话框ref:MatDialogRef
。如何在您的案例中定义构造函数?是您的snackBar材质实例吗?我不需要取消()snackBar,我需要关闭dialogRef。你在寻找调用成功函数的组件吗?不,如果成功,我只需要触发它。dialogRef.close()在NotificationPopUpServiceService
中,在构造函数中,我们需要设置公共对话框ref:MatDialogRef
。如何在您的案例中定义构造函数?是您的snackBar材质实例吗?我不需要取消()snackBar,我需要关闭dialogRef。你在寻找调用成功函数的组件吗?不,如果成功,我只需要触发它。dialogRef.close()