在多个复选框中选择特定复选框时选中所有复选框,其中angular4中有[(ngModel)]

时间:2017-06-23 11:10:03

标签: angular checkbox

这里'n'是增量值,默认情况下为0,当我点击“下一步”时,它增加1 ,分别退出对象

statement 1:
============

#let option of question[0].options

 here,lets assume "option" will have 1st question's option. and outputs the 
 following using *ngFor

 **<input name="0"  value="{{q1_option_value}}" [(ngModel)]="option_value[0]" 
type="checkbox"/><span>{{q1_option_value}}</span>**

 **<input name="1"  value="{{q1_option_value}}" [(ngModel)]="option_value[1]" 
type="checkbox"/><span>{{q1_option_value}}</span>**

 =========================
'n' value incremented by 1
 =========================


 **<input name="0"  value="{{q2_option_value}}" [(ngModel)]="option_value[0]" 
type="checkbox"/><span>{{q2_option_value}}</span>**

 **<input name="1"  value="{{q2_option_value}}" [(ngModel)]="option_value[1]" 
type="checkbox"/><span>{{q2_option_value}}</span>**

现在,当我在question1的选项中选中一个复选框时,该选择会保持原样 下一个问题也是......

这是我的代码示例!

<form>
 <div class="choice">
  <div *ngFor="let option of question[n].options; let i = index">
   <input name="{{i}}"  value="{{option}}" [(ngModel)]="option_value[i]" 
    type="checkbox"/><span>{{option}}</span>
  </div>
 </div>
</form>

1 个答案:

答案 0 :(得分:1)

technologies_value是一个数组吗?如果有,你试过这个吗?

[(ngModel)]="technologies_value[i]"