我想使用选中和未选中
来检查值0或1
<div class="roadblock"> <input type="checkbox" class="checkbox_style1" id="roaddiv" [(ngModel)]="note.selected" /> </div>
<div class="roadtext"> Road block </div>
<div class="roadblock"> <input type="checkbox" class="checkbox_style1" id="devdiv" [(ngModel)]="note.selected" /> </div>
<div class="roadtext"> Deviation </div>
<div class="roadblock"> <input type="checkbox" class="checkbox_style1" id="changediv" [(ngModel)]="note.selected" /> </div>
<div class="roadtext"> Change in approach</div>
<div class="roadblock"> <input type="checkbox" class="checkbox_style1" id="techdiv" [(ngModel)]="note.selected" /> </div>
<div class="roadtext"> Tech help</div>
&#13;
答案 0 :(得分:6)
您可以使用ngModel
绑定中的表达式来翻译值:
[ngModel]="note.selected == 1 ? true : note.selected == 0 ? false : null" (ngModelChange)="note.selected = $event ? 1 : 0"
但这需要将[(ngModel)]
分为[ngModel]
和(ngModelChange)