Search code examples
angularjsangularjs-ng-repeatangular-ngmodel

Interview form with angularjs (repeat and model)


I want to make interview questions form with ng-repeat, where when i click submit, it will send all the data, so i need different ng-model for that.

Here is my code

<form role="form" name="interviewForm">
  <div class="pr_setportfolio_content interview_div" ng-show="setinterview == true">
       <div class="prterms_name_input" ng-repeat="interview in interview">
           <span class="prterms_input_text">
             {{interview.question}}
           </span>
           <textarea class="prterms_inputtextarea_name" ng-model="interview_answer" name="interview_answer" placeholder="Enter answer" msd-elastic auto-resize></textarea>
      </div>
    </div>
</form>

So, anyone have any idea how to make it?

Thank you


Solution

  • Use same model (for example interview.answer instead of interview_answer) for holding answers and then you can get answer for each question in same model. Just iterate on interview list and each index will hold one question and its answer

    <form role="form" name="interviewForm">
    <div class="pr_setportfolio_content interview_div" ng-show="setinterview == true">
      <div class="prterms_name_input" ng-repeat="interview in interview">
        <span class="prterms_input_text">
          {{interview.question}}
        </span>
        <textarea class="prterms_inputtextarea_name" ng-model="interview.answer" name="interview_answer" placeholder="Enter answer" msd-elastic auto-resize></textarea>
      </div>
    
    </div>