0

I've been led to believe that it's better to use a child object on a scope rather than adding straight to the scope... e.g.

$scope.model.mystuff

is better than

$scope.mystuff

However, my first very simple bit of code using ne-repeat works when you do this...

$scope.myStuff = [{},{},{}]

<div ng-repeat="things in myStuff">Test</div>

If I run that I see the word Test 3 times. If I do the following though...

$scope.model.myStuff = [{},{},{}]

<div ng-repeat="things in model.myStuff">Test</div>

Then it doesn't loop at all. I'm sure I've just misunderstood this and the solution is very simle.

jonhobbs
  • 26,684
  • 35
  • 115
  • 170
  • You don't really need a child object as much as you need an array of objects (not an array of primitives) when using ng-repeat. Seee [this answer](http://stackoverflow.com/questions/14049480/what-are-the-nuances-of-scope-prototypal-prototypical-inheritance-in-angularjs/14049482#14049482) -- look for the bolded "ng-repeat" section -- if you want the full story. – Mark Rajcok Dec 28 '12 at 02:57

1 Answers1

1

Next time, if you provide a jsfiddle, it might make things easier :)

The problem seems to be how you declared

$scope.model.myStuff = [{},{},{}]

$scope.model didn't exist at that time, so I just quickly added it the line before like so:

$scope.model = {}
$scope.model.myStuff = [{},{},{}]

And then the ng-repeat worked, outputting test 3 times

jsfiddle: http://jsfiddle.net/rtCP3/33/

Mathew Berg
  • 28,625
  • 11
  • 69
  • 90