Angularjs ng-repeat is not taking values

Asked

Viewed 681 times

1

I’m returning a json with this code:

$scope.movies = angular.toJson(results, true);

and Getting this json: http://pastebin.com/87tJm8XE

And trying to get the data with this:

<ion-item ng-repeat="movie in movies">
    {{movie.title}}
</ion-item>

but I was making a mistake:

Error: [ngRepeat:dupes] Duplicates in a Repeater are not allowed. Use 'track by' Expression to specify Unique Keys.

so I tried that:

 <ion-item ng-repeat="movie in movies track by $index">
     {{movie.title}}
 </ion-item>

but now I can’t get the values. {{Movie.title}} returns empty.

  • 2

    Looks like you asked on the wrong website... here’s the OS at portuguese!

  • 2

    Gee, I haven’t seen it, sorry, I’ve edited it

1 answer

2

I don’t understand why you are turning the object into a JSON string. I don’t think it is appropriate.

Suggestion 1:

$scope.movies = results.data.results;

And use your original HTML:

<ion-item ng-repeat="movie in movies">
    {{movie.title}}
</ion-item>

Suggestion 2:

$scope.movies = results;

And in HTML:

<ion-item ng-repeat="data.results in movies">
    {{movie.title}}
</ion-item>
  • Thank you very much.I used the first option and it worked. I took a ready example and it turns the object into string json, I didn’t know what that was actually.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.