代码之家  ›  专栏  ›  技术社区  ›  Keerthi Reddy Yeruva

将数据传递到角度6中的引导模式

  •  -1
  • Keerthi Reddy Yeruva  · 技术社区  · 7 年前

    我正在尝试在我的项目中添加模式,这样如果我单击一个链接,模式将显示该特定链接的名称。

    但它给了我一个错误

    请查看下面的链接

    link for modal

    2 回复  |  直到 7 年前
        1
  •  4
  •   Martin Adámek    7 年前

    最好使用引导程序的角度版本来完成这项工作,这样可以很好地检测角度变化。

    例如 https://ng-bootstrap.github.io/#/components/modal/examples

    然后,您将拥有一个表示模式的组件,要将数据传递给它,只需声明公共属性并执行以下操作:

    const modalRef = this.modalService.open(YourModalComponent);
    (modalRef.componentInstance as YourModalComponent).yourProperty = yourValue;
    

    顺便说一下,要修复您所说的错误,您可以使用 attr 属性绑定,如下所示:

    <button type="button" class="btn btn-primary" data-toggle="modal" [attr.data-target]="'#' + products.name">
    

    它将修复错误,但模式仍然不起作用,看起来您还缺少CSS。

        2
  •  0
  •   Keerthi Reddy Yeruva    7 年前

    从得到答案 this link

    更新中的代码

    stackblitz line

    我们应该使用 <button type="button" class="btn btn-primary" data-toggle="modal" [attr.data-target]="'#'+products.name"> {{products.name}} </button>