angular - 在角度 8 中显示隐藏 div onClick 动态添加的单选按钮
问题描述
我需要动态添加单选按钮及其关联<div>
。
<li *ngFor="let ins of insuredPatientDetails">
<div class="p-10">
<label class="paymentcard_check">{{ins.primaryPayerName}}
<span *ngIf="ins.patientPaymentType === 0">(Self insured)</span>
<input type="radio" name="patientPayee" onchange="viewPatView(ins.insuranceInformationId)">
<span class="checkmark"></span>
</label>
</div>
<div class="col-md-12 b-t p-15 patId{{ins.insuranceInformationId}}">
<p>show hide me</p>
<p>{{ins.insuranceInformationId}}</p>
</div>
</li>
因此,如果单击第一个单选按钮,我需要显示其 div。同样,应该根据其选定的单选按钮显示 div。
解决方案
在 HTML 页面中,
<li *ngFor="let ins of insuredPatientDetails">
<div class="p-10">
<label class="paymentcard_check">{{ins.primaryPayerName}}
<span *ngIf="ins.patientPaymentType === 0">(Self insured)</span>
<input type="radio" name="patientPayee" value="{{ins.insuranceInformationId}}" (change)="viewPatView($event)">
<span class="checkmark"></span>
</label>
</div>
<div class="col-md-12 b-t p-15" *ngIf='"patId"+ins.insuranceInformationId === patId'>
<p>show hide me</p>
<p>{{ins.insuranceInformationId}}</p>
</div>
</li>
在 ts 文件中,
viewPatView(event){
this.patId = "patId"+event.target.value;
console.log(this.patId);
}
这样我可以解决问题,感谢您的帮助
推荐阅读
- eclipse - scala中的尾递归,这里我在eclipse IDE中运行scala代码,但没有输出
- javascript - 如何在 WebStorm UML 图中添加或删除元素
- ios - removeFromSuperview() 几个子视图
- mapbox-gl-js - Mapbox 中的“step”表达式是如何工作的?
- git - 如何在不签出的情况下推送本地功能分支?
- python - time.clock() 和 App Engine 日志时间之间的时间非常不同
- android - 是否可以过滤数组列表中的结果,然后将该列表添加到数组适配器?
- ios - watchOS App 未安装在 xcode 中的 watch / 神奇出现的文件上
- npm - 无法创建 angular6 项目
- c# - 如何从列表中获取值