I am trying to learn angular. I am having a hard time understanding part of this: http://www.learn-angular.org/#!/lessons/repeaters
In that example we're looping through a collection and displaying each element. Easy enough.
What I don't understand is: the collection is named "products" and each element is referred to as "product" no where in the JS code is the word product. How does angular know to call the element by "product"? Does a collection have to be plural and an element singular in name?
The identifier is assigned in the view (aka, the HTML):
<tr ng-repeat="product in products">
ng-repeat takes an expression that defines the identifier it will assign elements in the collection. So, in this case, you bind each item in
product. This is then accessible in the scope, so any child element of the
tr can access
product on the scope as
You can name the identifier anything you want.
product in products is equally as valid as
bananas in apple, so long as your collection is on
$scope.apple and you use the identifier
bananas to refer to the item in each collection.