Cazs
Cazs

Reputation: 21

AngularJS how acces data nested Json?

I'm trying to get a "thumbnail" image of a post in wordpress. But I am not able to access nested JSON data I created a jsFiddle link so you can see an example and may finish my html and AngularJS controller.

I might have to create a filter. But I can not, I'm stuck. The goal is to get that thumbnail nested and place it as an image src.

 {
        "ID": 45,
        "title": "Lista Generada",
        "status": "publish",
        "type": "post",
        "modified_gmt": "2015-03-11T21:04:47+00:00",
        "featured_image": 
    {
        "ID": 46,
        "title": "eCommerce-checklist",
        "status": "inherit",
        "type": "attachment",
        "is_image": true,
        "attachment_meta": 
    {
        "width": 1000,
        "height": 857,
        "file": "2015/03/eCommerce-checklist.jpg",
        "sizes": 
    {
        "medium": 
    {
        "file": "eCommerce-checklist-300x257.jpg",
        "width": 300,
        "height": 257,
        "mime-type": "image/jpeg",
        "url": "http://localhost/wp-content/uploads/2015/03/eCommerce-checklist-300x257.jpg"
    },
    "post-thumbnail":
                    {
                        "file": "eCommerce-checklist-825x510.jpg",
                        "width": 825,
                        "height": 510,
                        "mime-type": "image/jpeg",
                        "url": "http://localhost/wp-content/uploads/2015/03/eCommerce-checklist-825x510.jpg"
                    }
                },
            }
        },
    }

Upvotes: 0

Views: 95

Answers (2)

Nader
Nader

Reputation: 953

First of all "post-thumbnail" is not valid and You should change - to _

Then you can access to your post_thumbnail.

post.featured_image.attachment_meta.sizes.post_thumbnail.url

Upvotes: 0

HankScorpio
HankScorpio

Reputation: 3651

Use ng-src, not src. Also, your JSON is not valid.

Upvotes: 0

Related Questions