angular - Angular:根据单选按钮值更改更改复选框的选中状态
问题描述
我想根据单选按钮的值检查所有选中的框,反之亦然未选中的单选按钮单击。我正在尝试通过以下方式实现它。但我不能这样做。
组件 HTML
<label class="radio-inline">
<input type="radio" name="sel" value="0" [(ngModel)]="clientSelectionType">Select All
</label>
<label class="radio-inline">
<input type="radio" name="sel" value="1" [(ngModel)]="clientSelectionType">Unselect All
</label>
<div class="form-group">
<h3> radio button </h3>
<label class="radio-inline">
<input type="checkbox" [checked]="clientSelectionType===0"> Test 1
</label>
<label class="radio-inline">
<input type="checkbox" [checked]="clientSelectionType===0"> Test 2
</label>
<label class="radio-inline">
<input type="checkbox" [checked]="clientSelectionType===0"> Test 4
</label>
<label class="radio-inline">
<input type="checkbox" [checked]="clientSelectionType===0"> Test 3
</label>
</div>
StackBlitzLink:https ://stackblitz.com/edit/angular-ffuhsz 。我怎样才能做到这一点?
解决方案
问题是string
vsnumber
比较。你在做什么clientSelectionType === 0
,这是'0' === 0
。它是一个字符串的原因是因为您正在绑定这样的值:value="1"
在收音机上。这会产生一个字符串值。尝试使用绑定括号的值:
<input type="radio" name="sel" [value]="1" [(ngModel)]="clientSelectionType">
推荐阅读
- python - 将跨两列的 R mutate 条件转换为 Python
- jquery - 数据表排序 - 通过单击标题进行排序
- amazon-web-services - 未知令牌: IDENT ,解码/解析 terraform 文件时
- python - 在使用 lxml XPATH 搜索多个元素时需要帮助
- xcode - 将代码括在大括号中并在 Xcode 中自动缩进?
- python - 将 CMake 指向 conda env 中的正确 Python 标头?
- javascript - 没有 React 的 HTML 和 Typescript 按钮?
- php - 如何使用 PHP 显示计数帖子?
- python-3.x - 在子类python3中获取超类输入参数
- filter - 如何过滤字符串中的某些元素