我希望在服务中获得相同的BsModalRef引用。有可能吗?
openModal() {
this.bsModalRef = this.modalService.show(SomeComponent, {
initialState: {
title: 'Modal title',
data: {},
},
});
console.log(this.modalRef); // this gives the opened modal reference
this.service.mimic(); // this return a new instance of the bsModalRef service.
}我是service.mimic
mimic() {
console.log(this.bsModalRef);
}发布于 2022-08-16 04:52:22
我想您想要访问服务中的引用。在服务中创建一个变量,然后将值赋值如下。测试服务中的变量应该是一个数组!
openModal() {
this.bsModalRef = this.modalService.show(SomeComponent, {
initialState: {
title: 'Modal title',
data: {},
},
});
//using a test service
this.testService.modalRefs.push(this.modalRef);
console.log(this.modalRefs); // this gives the opened modal reference
this.service.mimic(); // this return a new instance of the bsModalRef service.
}
closeModal() {
this.modalService.hide();
//using a test service
this.testService.modalRefs.pop();
}可以在使用服务的任何地方访问modalRef of testService。当您关闭前一个模型时,我们可以删除数组中的最后一个元素,这样数组中的最后一个元素将永远是打开的模态,请改进这种方法以满足您的需要!
https://stackoverflow.com/questions/73368875
复制相似问题