0

I have an issue with Drag and Drop with Angular JS on my Quiz

The code works fine if I just use one object simulated here by the index number i.e. as shown below myQuest[0].answers

    ng-repeat="myQuestion in myQuest | limitTo: 5">
      <p class="txt">{{myQuestion.question}} ?</p>

      <li   class=""
            lr-drag-src="reorder" lr-drop-target="reorder"
            ng-repeat="Answer in myQuest[0].answers ">
          <img ng-src="{{ Answer.image }}">
        {{Answer.id}}
      </li>
          <p class="txt">{{analysis}}</p>
          <div class="feedback">

but fails when I use the code below which is required to move to next question i.e myQuest[$index].answers of the question to be answered Symptoms: The Drag and Drop reorder image reorders by moving an answer to the next object /question and not the question been answered

  ng-repeat="myQuestion in myQuest | limitTo: 5">
      <p class="txt">{{myQuestion.question}} ?</p>

      <li   class=""
            lr-drag-src="reorder" lr-drop-target="reorder"
            ng-repeat="Answer in myQuest[$index].answers ">
          <img ng-src="{{ Answer.image }}">
          {{Answer.id}}
      </li>
          <p class="txt">{{analysis}}</p>
          <div class="feedback">

         

I've tried track by $index on both parent and child ng-repeats to no avail

georgeawg
  • 48,608
  • 13
  • 72
  • 95
user3265817
  • 99
  • 1
  • 13
  • I suppose `myQuest[&index].answers` has a typo and your actual code is `myQuest[$index].answers`, right? please take a look [here](https://stackoverflow.com/questions/25094201/nested-ng-repeat-parent-index-and-index/25094542) and [here](https://stackoverflow.com/questions/15256600/passing-2-index-values-within-nested-ng-repeat). – lzagkaretos Dec 13 '20 at 11:50
  • Could you reproduce the bug in a JsFiddle so that we can try fixing it? – Eloims Dec 13 '20 at 15:44

1 Answers1

0

This fixed it thankyou lzagkaretos

       ng-repeat="myQuestion in myQuest track by $index | limitTo: 5"
       ng-init="**questionIndex** = $index" >
      <p class="txt">{{myQuestion.question}} ?</p>

      <li class=""

          lr-drag-src="reorder" lr-drop-target="reorder"
          ng-repeat="Answer in myQuest****[questionIndex]**.answers"
          ng-init="answerIndex = $index" >
georgeawg
  • 48,608
  • 13
  • 72
  • 95
user3265817
  • 99
  • 1
  • 13