Scenario:
<input [(ngModel)]="TryToPassDataModel.name">;
btn.onClick = function() {
this.bsModalRef =
this.modalService.open(ChildComponent, TryToPassDataModel);
}
This works in ngx-bootstrap, but how to implement this in nb-bootstrap? (it looks like such a simple idea)
To pass data into the modal body jquery methods are used. jQuery is similar to JavaScript, however jQuery methods are simple and easier to implement. jQuery reduces the lines of code. The article demonstrates two examples where data is passed into the modal body from the HTML document body.
If you pass a component type as content, then instances of those components can be injected with an instance of the NgbActiveModal class. You can then use NgbActiveModal methods to close / dismiss modals from "inside" of your component. Also see the NgbModalOptions for the list of supported options. dismissAll.
Looks like you're not using the API properly. The plugin expects the params to be passed as @Input(). Something like this would work :
const modalRef = this.modalService.open(NgbdModalContent);
modalRef.componentInstance.name = 'World';
Make sure you add a @Input for your model in ModalContent component!
See the doc for more info : https://ng-bootstrap.github.io/#/components/modal/examples
In Angular 8 using ng-bootstrap Modal to pass data from parent component to modal
Source Link
openModal() {
const modalRef = this.modalService.open(MyBootstrapModalComponent,
{
scrollable: true,
windowClass: 'myCustomModalClass',
// keyboard: false,
// backdrop: 'static'
});
let data = {
prop1: 'Some Data',
prop2: 'From Parent Component',
prop3: 'This Can be anything'
}
modalRef.componentInstance.fromParent = data;
modalRef.result.then((result) => {
console.log(result);
}, (reason) => {
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With