首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ngx自举模态在角上的参考值

ngx自举模态在角上的参考值
EN

Stack Overflow用户
提问于 2022-08-16 04:43:30
回答 1查看 207关注 0票数 0

我希望在服务中获得相同的BsModalRef引用。有可能吗?

代码语言:javascript
复制
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

代码语言:javascript
复制
mimic() {
    console.log(this.bsModalRef);
  }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-16 04:52:22

我想您想要访问服务中的引用。在服务中创建一个变量,然后将值赋值如下。测试服务中的变量应该是一个数组!

代码语言:javascript
复制
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。当您关闭前一个模型时,我们可以删除数组中的最后一个元素,这样数组中的最后一个元素将永远是打开的模态,请改进这种方法以满足您的需要!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73368875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档