angular - 如何在角度 7 中关闭另一个组件的模态?
问题描述
有没有办法从另一个组件关闭角材料模态?我已经尝试过使用服务,但它似乎不起作用。下面是我的代码。
modal.service.ts
private modalClose = new Subject<any>();
setModalClose(){
this.modalClose.next();
}
getModalClose(){
return this.modalClose.asObservable();
}
发送文件.ts
onClick(){
this.modalService.setModalClose();
}
接收文件.ts
subscribe: Subscription;
constructor(
private _modalService: ModalService
private dialogRef: MatDialogRef<SaveDashboardModalComponent>){
this.subscribe = this._modalService.getModalClose()
.subscribe(()=>{
this.dialogRef.close();
})
}
解决方案
尝试这样的事情。
constructor(private dialog: MatDialog)
setModalClose(){
this.dialog.close();
}
// Here will be good if you open the dialog.
openModal() {
this.dialog.open(name of the dialog Component);
然后在另一个组件中只调用。
this._modalService.setModalClose();
推荐阅读
- swift - SwiftUI 侧边栏列表部分应默认折叠
- python - 没有得到可重现的结果 TensorFlow-Keras-Google Collab
- c++ - CMAKE GLFW 链接问题
- specifications - 为什么 TLC 在有效状态上报告错误?
- react-native - React Native:FlatList 闪烁的项目列表很大,而不是较小的列表
- flutter - Dart Analyzer 在 flutter clean 或 flutter run 时终止
- go - 如何为消费者添加 oauthbearer 支持 - 如何刷新 jwt 令牌
- cvxopt - 如何在 cvxopt 中禁用 GLPK 求解器的日志输出?
- jquery - 在 asp.net mvc 中使用 jQuery datepicker 默认值不为空
- java - 将文件内容作为输入读取到控制台