[英]Binding model dynamically in angular2
I want to bind modal dynamically in Angular2. 我想在Angular2中动态绑定模式。 Here is my code
这是我的代码
<div *ngFor="let interest of interest_data;" class="row">
<a class="btn btn-xs btn-link" data-toggle="modal" data-target="#{{interest.id}}">
<i class="fa fa-pencil"></i>
</a>
</div>
and the target modal element is as below 并且目标模态元素如下
<div *ngFor="let interest of interest_data;">
<div class="modal fade" id="interest.id" tabindex="-1" role="dialog"
aria-labelledby="modalLabel" aria-hidden="true">
</div>
</div>
Its not working . 它不起作用。 What is the proper way of doing it ?
正确的做法是什么?
Try using [attr.data-target] and [attr.id]. 尝试使用[attr.data-target]和[attr.id]。 I think you want to do something like this:
我认为您想做这样的事情:
<div *ngFor="let interest of interest_data;">
<div>
<a class="btn btn-xs btn-link" data-toggle="modal" [attr.data-target]="'#' + interest.id">
open modal
<i class="fa fa-pencil"></i>
</a>
</div>
<div class="modal fade" [attr.id]="interest.id" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
modal data
</div>
</div>
</div>
</div>
Make sure to include JQuery and bootstrap.js. 确保包括JQuery和bootstrap.js。
Cheers 干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.