Is Angular recognizing plurality?


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-angularjs/lessons/your-first-app/exercises/your-first-app-ng-repeat-ii?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>This is just a general question and not really a problem I’m having. I just don’t understand how it works. In the main controller, the “products” portion looks like this:

$scope.products = [
{
name: ‘The Book of Trees’,
price: 19,
pubdate: new Date(‘2014’, ‘03’, ‘08’),
cover: ‘img/the-book-of-trees.jpg’
},
{
name: ‘Program or be Programmed’,
price: 8,
pubdate: new Date(‘2013’, ‘08’, ‘01’),
cover: ‘img/program-or-be-programmed.jpg’
}
]

In all of the previous examples, the HTML refers to the $scope.whatever is here. In the controller, it’s called “products,” plural. But in the HTML it refers to “product” singular. As in something like this:

{{ **product**.name }}

{{ **product**.price | currency }}

{{ **product**.pubdate | date }}

So why does that work? I’m used to other kinds of code and creating variables to store information in. The process seems very similar, yet somehow the syntax operates differently, using a singular word to get information stored in a plural form. I’m just trying to understand.


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.