0

Here 'n' is incremental and 0 by default when i click "NEXT" it increments by 1 , which retirives objects respectively

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>**

now when i select a checkbox in question1's option, that selection presist to next question also...

Here is my code sample !

<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>
  • this might help you check it https://stackoverflow.com/questions/43423333/angular-2-how-to-get-the-multiple-checkbox-value – Arun Kumaresh Jun 23 '17 at 12:27

1 Answers1

2

Is technologies_value an array? If so have you tried this?

[(ngModel)]="technologies_value[i]"
Rob Zuber
  • 131
  • 3
  • 1
    OK. Well you have multiple checkboxes so the ngModel needs to be able to bind each checkbox to its own value. At the moment you are binding them all to the same variable (technologies_value) so they all get the same value. – Rob Zuber Jun 23 '17 at 11:55
  • thanks for your answer, but after implementing your solution i met with another problem so i re-edited my question please take a look – Gokulraj Mahadheeraa Jun 23 '17 at 12:28
  • 1
    OK. I may not entirely understand the example but the ngModel will need to have one value for every separate checkbox. In your example you have: option_value[0] and then option_value[0] repeated again for the next 'N'. If N goes up to 1 (meaning it was zero and then a 1), then you would need option_value[0], option_value[1], option_value[2] and option_value[3] – Rob Zuber Jun 23 '17 at 12:46
  • {{option}} **here, n performs as index & i performs as key -- hence i solved this already**.. thank you guys... – Gokulraj Mahadheeraa Jun 23 '17 at 14:41