I\'m trying to send data to a custom modal content component so I can call it from any other component and not repeat code. I\'m new to Angular 2 and have followed the \"Com
I solved it! Here's how to do it:
In the component(from where you are opening the modal) do this:
const modalRef = this.modalService.open(ModalComponent);
modalRef.componentInstance.passedData= this.dataToPass;
modalRef.result.then(result => {
//do something with result
}
In the modal component(receiving end):
export class ModalComponent {
passedData: typeOfData; // declare it!
someFunction() { // or some lifecycle hook
console.log(this.passedData) // and then, use it!
}
// rest of the ModalComponent
}