【发布时间】:2017-12-14 21:47:56
【问题描述】:
我正在尝试开发 angular2 应用程序。我在页面上的每个卡片页脚中有 9 个按钮。单击任何按钮或锚标记应打开引导模式,但每次单击都必须具有不同的内容。 modal 的模板必须相同,只是每个单击的按钮的内容都必须不同。现在,模式会在具有相同模板和内容的每个按钮上打开。如何将 ID 与按钮关联,以便单击导致相同的模态模板但不同的内容。
这是我在 sample.component.html 中的代码
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-content">
<div class="card-header-orange">
<h1 class="card-heading">Card Header Blue</h1>
</div>
<div class="card-body">
<p class="card-p">
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour,
or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there
isn't anything embarrassing hidden in the middle of text.
</p>
</div><br>
<div class="card-footer">
<button (click)="openModal(template)" class="btn btn-primary">Learn More</button>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-content">
<div class="card-header-orange">
<h1 class="card-heading">Card Header Blue</h1>
</div>
<div class="card-body">
<p class="card-p">
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour,
or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there
isn't anything embarrassing hidden in the middle of text.
</p>
</div><br>
<div class="card-footer">
<button (click)="openModal(template)" class="btn btn-primary">Learn More</button>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-content">
<div class="card-header-orange">
<h1 class="card-heading">Card Header Blue</h1>
</div>
<div class="card-body">
<p class="card-p">
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour.
</p>
</div><br>
<div class="card-footer">
<button (click)="openModal(template)" class="btn btn-primary">Learn More</button>
</div>
</div>
</div>
</div>
</div>
这是我的模态模板:
<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">×</span>
</button>
</div>
<div class="modal-body">
This is a modal.
</div>
【问题讨论】:
标签: angular twitter-bootstrap-3 angular2-template