I am having some trouble with using AngularJS ng-repeat. Here is what I have:
<div ng:show="selected == 3"> <div class="columns"> <textarea rows="4" data-ng-model="modal.data.answer[1].text" cols="91">1</textarea> </div> <div class="columns"> <label>Explanation</label> <textarea rows="2" data-ng-model="modal.data.answer[1].explanation" cols="91"></textarea> </div> <div class="columns"> <div class="colx2-left"> <span class="label">Correct</span> <input type="checkbox" data-ng-model="modal.data.answer[1].correct" class="check-box"><input type="hidden" value="false" name="Details[0].Correct"> </div> <div class="colx2-right"> <label>Image File</label> <input type="text" data-ng-model="modal.data.answer[1]image" class="full-width"> </div> </div> </div>
The modal.data.answer array will always have six elements. Can I use ng-repeat to create the HTML for these and have it repeat even the [x] numbers in the array and have it increment the number on the first line for "selected =" from 3 to 8 ?
As far as I know I can use <div ng-repeat="t in [3,4,5,6,7,8]"> </div>
but how can I get the values of t into things like:
data-ng-model="modal.data.answer[1].text"
AngularJS ng-repeat Directive The ng-repeat directive repeats a set of HTML, a given number of times. The set of HTML will be repeated once per item in a collection. The collection must be an array or an object.
But ng-repeat is not the right thing to use when you have large datasets as it involves heavy DOM manipulations. And you should consider using ng-repeat with pagination. You can consider using transclusion inside a custom directive, to achieve the behavior you are looking for without using ng-repeat.
ng-repeat created inherited child scope for each element of collection, while *ngFor creates local variable in the that block.
Solution 1 There are two mistakes in your code: In your table, you have to wrap the properties between {{ and }}, for example {{employee. Fname}} instead of just employee. Fname .
your edit is heading in the right way, you can iterate through a list of integers easily, the you just use the value of you index like that
<div ng-repeat="t in [3,4,5,6,7,8]"> .... data-ng-model="modal.data.answer[t].text" ...
I made a fiddle if you want to try http://jsfiddle.net/DotDotDot/tweyS/ (the input field is just here to change the selected value, as in your code sample, in order to display the right fields)
have fun
Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys.
<div ng-repeat="n in [42, 42, 43, 43] track by $index"> {{n}} </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With