需求是使用ngFor获取列表,单击选项卡以显示引导模式,但每个模态ID在列表中是相同的,导致每个模态的内容是第一次采访,现在的想法是获取索引,索引将传递给id。现在的问题是如何传入索引,这个想法是正确的吗?
<tr *ngFor="let interview of interviews; let i = index" role="row" class="gradeA">
<td class="col-sm-2" style="text-align: left;">{{ interview.company.name }}</td>
<td class="col-sm-1" style="text-align: left;">{{ interview.inviter.real_name }}</td>
<td class="col-sm-1" style="text-align: left;" *ngIf="interview.interviewee.user_id==0">未知</td>
<td class="col-sm-1" style="text-align: left;" *ngIf="interview.interviewee.user_id!=0">{{ interview.interviewee.real_name }}</td>
<td class="col-sm-1" style="text-align: left;" *ngIf="interview.notice_type==0">
<a data-toggle="modal" data-target="modal">短信</a>
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">通知内容</h4>
</div>
<div class="modal-body">
<span style="font-weight:bold;">公司名称:</span><p>{{ interview.company.name }}</p>
<span style="font-weight:bold;">面试官:</span><p>{{ interview.inviter.real_name }}</p>
<span style="font-weight:bold;">应聘者:</span><p>{{ interview.interviewee.real_name }}</p>
<span style="font-weight:bold;">通知内容:</span><p>{{ interview.notice_content }}</p>
</div>
</div>
</div>
</div>
</td>
答案 0 :(得分:0)
我们可以使用此解决方案,只需创建1个对话框弹出窗口并将其传递给selectedInterview对象。
selectedInterview: any;
showPopup(interviewObj) {
this.selectedInterview = interviewObj;
}
我们将模板分为2个部分,1个用于循环访问,1个用于对话框弹出
<tr *ngFor="let interview of interviews; let i = index" role="row" class="gradeA">
<td class="col-sm-2" style="text-align: left;">{{ interview.company.name }}</td>
<td class="col-sm-1" style="text-align: left;">{{ interview.inviter.real_name }}</td>
<td class="col-sm-1" style="text-align: left;" *ngIf="interview.interviewee.user_id==0">未知</td>
<td class="col-sm-1" style="text-align: left;" *ngIf="interview.interviewee.user_id!=0">{{ interview.interviewee.real_name }}</td>
<td class="col-sm-1" style="text-align: left;" *ngIf="interview.notice_type==0">
<a data-toggle="modal" (click)="showPopup(interview)" data-target="modal">短信</a>
</td>
请注意: ng-container 检查selectInterview是否未定义以在弹出窗口中显示
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">通知内容</h4>
</div>
<div class="modal-body">
<ng-container *ngIf="selectedInterview !== undefined">
<span style="font-weight:bold;">公司名称:</span><p>{{ selectedInterview.company.name }}</p>
<span style="font-weight:bold;">面试官:</span><p>{{ selectedInterview.inviter.real_name }}</p>
<span style="font-weight:bold;">应聘者:</span><p>{{ selectedInterview.interviewee.real_name }}</p>
<span style="font-weight:bold;">通知内容:</span><p>{{ selectedInterview.notice_content }}</p>
</ng-container>
</div>
</div>
</div>
</div>