How do I set ng-bootstrap modal component content members?

萝らか妹 提交于 2019-12-24 15:05:38

问题


This is the open method from the sample in the documentation, using a component as content:

open() {
  const modalRef = this.modalService.open(NgbdModalContent);
  modalRef.componentInstance.name = 'World';
}

What I would like to do is to use the component in a similar fashion below and able to set the name.

open(content) {
  this.modalService.open(content).result.then((result) => {
    this.closeResult = `Closed with: ${result}`;
  }, (reason) => {
    this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
  });
}

How can I do that?

I am relatively new to both Typescript and Angular 5.


回答1:


That was a really newbie question.

The solution is

open() {
  const modalRef = this.modalService.open(NgbdModalContent);
  modalRef.componentInstance.name = 'World';
  modalRef.result.then((result) => {
    this.closeResult = `Closed with: ${result}`;
  }, (reason) => {
    this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
  });
}


来源:https://stackoverflow.com/questions/48648711/how-do-i-set-ng-bootstrap-modal-component-content-members

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!