Ng-repeat, <div ng-repeat="n in apps" class="card"> <app-info info="apps"></app-info> </div>


Can somebody help me with this problem? I am not sure if my syntax is right.

my code:


expected .card to have an attribute ng-repeat

the code is not displayed, in the message box, I don't know why


Try this


It's correct your sintaxis, only you need put this div in first place


 <div class="main" ng-controller="MainController">
  <div class="container">
    <div ng-repeat="app in apps" class="card">
      <app-info info="app"></app-info>

    <div class="card"><app-info info="move"></app-info></div>
    <div class="card"><app-info info="shutterbugg"></app-info></div>
    <div class="card"><app-info info="gameboard"></app-info></div>
    <div class="card"><app-info info="forecast"></app-info></div>


but why it should be in first place , i mean what is the logic behind this :smile:thanks in advance


Its not about first place. Your mistake was that you used:

<div ng-repeat=“n in apps” class=“card”> <app-info info=**“apps”**></app-info> </div>
instead of
<div ng-repeat=“n in apps” class=“card”> <app-info info=**“n”**></app-info> </div>
<div ng-repeat=**“app in apps”** class=“card”> <app-info info=**“app”**></app-info> </div>


So I actually have a question about what this line of code is accessing. I get how to make it run, but would love a little explanation as to what is corresponding to what. Thanks very much!


It works. Thank you very much.


Thank you @raftael, that was extremely helpful.


Why should i write 4 divs again if i am already using ng-repeat??


We don't need 4 divs, we are repeating $scope.apps, so
<div ng-repeat="app in apps" class="card"> then
in the custom directive "app-info" we just need to put the repeated "app"
<app-info info="app"></app-info>


Had some difficulty understanding this one as well but I managed to do it. Here is the syntax:

<div ng-repeat="app in apps" class="card">
<app-info info="app"></app-info>

The problem that I had was, its not showing the correct content then I realized you have to put the ng-repeat first before you add the class as shown above.

and also ake sure you delete the first 4 divs for each of the cards for cleanliness. Hope this helps :slight_smile:


Where does "app in apps" come from? Or I mean is "app" supposed to be predefined?


apps is the object
app is a variable-name
Internally they are using a so-called FOR-IN loop.

Look above where somebody used "n in apps"
and then also be aware of the other changes you will have to make.


My question is, when and where is the variable-name, app, defined as a variable?


As soon as you use
ng-repeat="app in apps"


Could I call app a parameter instead?


Use google search if you want to read some
== the Book ==
angularjs ng-repeat directive site:

== discussions / opinions ==
angularjs ng-repeat


No, by saying

ng-repeat="app in apps" you are creating a loop. apps comes from $scope.apps, you have an array of multiple apps

ng-repat="x in y" means, loop through the array of y (or apps) and assign each one to x (or app).

you could write it: ng-repeat="foo in apps" or ng-repeat="thisIsOneItemInMyArray in apps" or ng-repeat="shabalamalam in apps"

You are basically instantiating the variable when you do that.


ya its true,,, but that code is not working


Its about the position only,, I wrote the correct code but still it was showing error but when I changed the position with the same code then that error got removed.