【发布时间】:2017-09-11 22:27:42
【问题描述】:
我正在尝试获取选中的单选按钮并将值添加到数组中。目前,我无法删除之前选中的单选按钮,所以基本上每次我选择单选按钮时它都会不断添加到数组中。
item.component.ts
displaySelectedConditions(event) {
if(event.target.checked) {
this.selectedConditionsArr.push(event.target.value);
}
}
item.component.html
<ul class="dropdown-menu">
<li *ngFor="let item of filteredItems | funder "> //generates 4 items
<a><input type="radio" (change) = "displaySelectedConditions($event);"
name="funder" id="{{item}}" value="{{item}}">
<label for="{{item}}" >{{item}}</label></a>
</li>
</ul><!-- Dropdown Menu -->
【问题讨论】:
-
Plunker 会很有帮助。
-
为什么要使用数组?由于任何时候都只选中一个单选按钮,所以不能只保留新选择的值吗?
-
是的,我可以拥有,但我还有 3 个广播组。所以我想,Array 将是保留它们的干净方式。检查它在 plunker plnkr.co/edit/DCxaGkQFNs3cUDHnp6yG
标签: javascript angular