问题
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