user1012032
user1012032

Reputation:

Access items in an array from json using ng-repeat

Json file:

{
"id":"7",  
"date":"1 Jan",  
"images":["507f42c682882","507e24b47ffdb","507e2aeca02d5","507e2b19663a9"]  
}

in my controller I have

$http.get('urlToJsonFile).
    success(function(d){
        console.log(d);
        $scope.item = d;
    });

in my partial view I can print the id and date but when it comes to printing the images, it just doesnt work. Im doing it wrong. Why isnt there any output? Do you know how to fix this problem?

{{item.id}}:{{item.date}}
    <ul>
    <li ng-repeat="img in item.images">
    {{img}}
    </li>
    </ul>

Upvotes: 0

Views: 8384

Answers (2)

Mahbub
Mahbub

Reputation: 3118

It's working. See This JS Fiddle . Can you put your code in JSFiddle as to why it's not working for you ?

I've used your ajax response as hard coded collection.

'use strict';

var obj = {
    "id": "7",
    "date": "1 Jan",
    "images": ["507f42c682882", "507e24b47ffdb", "507e2aeca02d5", "507e2b19663a9"]
};

function Ctrl($scope) {
    $scope.item = obj;
}​

Upvotes: 1

holographic-principle
holographic-principle

Reputation: 19738

There are some known issues with ng-repeat and iterating over primitive types. Check this issue on github .

If possible, try to use objects as your array elements.

Upvotes: 1

Related Questions