使用ngx-bootstrap modal将数据传递给modal

哈维恩斯

我正在使用angular 8和ngx-boostrap打开模态并将数据从父级传递到模态。但是没有按预期工作。我应该怎么做才能使其正常工作?..这是我的stackblitz演示和代码

的HTML

<button type="button" class="btn btn-primary" (click)="openModal(template)">Open modal</button>
 
<ng-template #template>
  <div class="modal-header">
    <h4 class="modal-title pull-left">Modal</h4>
    <button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
    Just a modal with a {{initialState.data1}}
  </div>
</ng-template>

零件

openModal(template: TemplateRef<any>) {
    const initialState = {
    data1 : 'foo'
}
    this.modalRef = this.modalService.show(template, {initialState});
  }
沙阿

你可以这样使用

的HTML

<ng-template #template>
  <div class="modal-header">
    <h4 class="modal-title pull-left">Modal for data : {{ modalService.config.initialState.data1 }}</h4>
    <button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
    This is a modal.
  </div>
</ng-template>

零件

openModal(template: TemplateRef<any>) {
    const user = {
        data1 : 'foo'
      };
    this.modalRef = this.modalService.show(template, {
      initialState : user
    });
  }

而这个在线演示

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何将值传递给Bootstrap Modal的href链接?

如何使用Laravel,Bootstrap Modal和Ajax将数据发布并插入到DB中

使用ajax将数据传递到bootsrap modal时为空白

Bootstrap Modal-使用Javascript将数据传递到Modal

如何将数据传递给Modal ionic 2

将datepicker和timepicker值与ngx-bootstrap结合使用

订阅ngx-bootstrap modal中的模式组件更改

Angular 8 ngx-bootstrap modal找不到组件工厂

使用jQuery AJAX调用将数据传递给函数

Ngx-bootstrap modal:如何将数据传递到modal component.ts而不是html模板?

将对象的数据ID传递给Bootstrap Modal表单

如何在ngx-bootstrap-modal中添加模糊效果

使用模式时将数据传递给UIViewController

将值传递给Bootstrap Modal中的表单

使用Ajax加载模型时将数据传递给Bootstrap模型

使用javascript将数据传递给模态

使用HTML表单将数据传递给Javascript代码

Bootstrap Modal使用数据映像作为源

使用 setresult() 将数据传递给活动

如何将 Bootstrap Modal 表单数据传递给 Spring Boot 控制器

使用 Bootstrap Modal 从 Javascript 函数传递 MVC 数据

将 JavaScript 对象数据传递到 Bootstrap Modal

将 var 传递给 bootstrap modal,其中 php 将使用此值

使用 CollectionViewCell _Swift 将 Firebase 数据传递给 DetailView

Swift - 使用字典将数据传递给参数

ngx-bootstrap modal 单例问题

使用 React Bootstrap 将数据传递给自定义元素

如何使用 react 将数据传递给 Modal。编辑还是删除?

如何使用 ajax .post() 将数据传递给 php