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


#1

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

my code:



error:

expected .card to have an attribute ng-repeat

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


#2



Try this


#3

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

example:

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

    <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>
    
  </div>
</div>

#4

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


#5

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>
or
<div ng-repeat=**“app in apps”** class=“card”> <app-info info=**“app”**></app-info> </div>

#6

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!


#7

It works. Thank you very much.


#8

Thank you @raftael, that was extremely helpful.


#9

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


#10

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>


#11

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>
</div>

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:


#12

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


#13

@devace17769,
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.


#14

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


#15

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


#16

Could I call app a parameter instead?


#17

@devace17769,
Use google search if you want to read some
== the Book ==
angularjs ng-repeat directive site:https://docs.angularjs.org

== discussions / opinions ==
angularjs ng-repeat site:stackoverflow.com


#18

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.


#19

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


#20

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.