如何将数据从ModalService传递到组件 [英] How pass data from ModalService into component

查看:399
本文介绍了如何将数据从ModalService传递到组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ngx-bootstrap-modal将数据从模式服务传递到模式组件. 示例显示如下:

I'm trying to use ngx-bootstrap-modal to pass data from a modal service into a modal component. The examples show this:

this.modalService.show(ModalContentComponent, {initialState});

但是它没有显示ModalContentComponent实际上是如何消耗该状态的.我在调试器中玩耍,但从未见过我的组件正在获取该数据.

But it doesn't show how the ModalContentComponent actually consumes that state. I've played around in a debugger and I never see my component getting that data.

如何从组件访问它?

推荐答案

您也可以使用BsModalRef content

my-modal.component.ts

my-modal.component.ts

export class MyModalComponent {
  public myContent;
  constructor(){}
}

从其他组件调用模态

import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal';
...
    public modalRef: BsModalRef;

    constructor(public modalService: BsModalService){}

    public openModal() {
       this.modalRef = this.modalService.show(MyModalComponent);
       this.modalRef.content.myContent= 'My Modal Content';
    }
...

这篇关于如何将数据从ModalService传递到组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆