What is the meaning of the singular/plural syntax in, say, ng-repeat="product in store.products"
?

- 1,225
- 12
- 18
-
1https://docs.angularjs.org/api/ng/directive/ngRepeat – Jonathan de M. Jun 09 '14 at 20:00
-
1`product` has nothing to do with `store.products`. You could write `blahblah` in `store.products` – lucuma Jun 09 '14 at 20:03
-
Possible duplicate of [How does ng-repeat work?](https://stackoverflow.com/questions/20133429/how-does-ng-repeat-work) – dpren Dec 20 '18 at 18:17
3 Answers
Singular/plural is used just for common sense and code readability - it doesn't have to be singular/plural. You can do
ng-repeat="whatever in store.products"`
and then have the whatever
object available inside (like: <img ng-src="{{whatever.images[0]}}" />
).
In your case, store.products
can't be changed since it refers to an actual object, while product
is a completely custom name to be used in the repeat loop.
Fairly common in programming. Like the other answer said, it's similar to the for..in syntax.

- 37,421
- 4
- 57
- 85
This is essentially the same syntax as a Javascript for...in loop. It means for someTempVar in someArrayOrObject
.

- 7,165
- 2
- 33
- 39
The directive ng-repeat="product in products"
creates a new variable product
that you can reference inside your template. There is no singular/plural interpolation going on.

- 7,307
- 2
- 33
- 48