场景:
- ChildComponent - 有很多 ngModel 绑定(bind)元素。
<input [(ngModel)]="TryToPassDataModel.name">;
- 父组件 -
btn.onClick = function() {
this.bsModalRef =
this.modalService.open(ChildComponent, TryToPassDataModel);
}
这在 ngx-bootstrap 中有效,但如何在 nb-bootstrap 中实现呢? (看起来就是这么简单的想法)
最佳答案
您似乎没有正确使用 API。该插件期望参数作为@Input() 传递。这样的事情会起作用:
const modalRef = this.modalService.open(NgbdModalContent);
modalRef.componentInstance.name = 'World';
确保在 ModalContent 组件中为模型添加 @Input!
有关更多信息,请参阅文档:https://ng-bootstrap.github.io/#/components/modal/examples
关于angular - 如何将数据传递给 Angular ng-bootstrap 模态以进行绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48698665/