2014-04-29 109 views
1

我想從使用angularjs的json API中獲取圖像。 我正在使用一個html文件來獲取圖像,但我想我錯過了一些東西,它不起作用。 這裏是我的html:使用AngularJS和wordpress獲取來自JSON響應的圖像url

<li ng-repeat="post in posts"> 
    <a ng-click="clickToOpen({{post.id}})">{{post.title}}</a><p> img src="{{post.attachments.url}}"></p>  
</li> 

我的JSON:

"attachments": [ 
      { 
       "id": 15534, 
       "url": "http://www.grandlakebusinessjournal.com/wp-content/uploads/2013/02/Tera-Mirand-Shores-Platt-Phanse-One2.jpg", 
       "slug": "tera-mirand-shores-platt-phanse-one-3", 
       "title": "Tera Mirand Shores Platt Phanse One", 
       "description": "", 
       "caption": "", 
       "parent": 15455, 
       "mime_type": "image/jpeg", 
       "images": [] 
      } 

     ] 

回答

2

使用ng-src,小心你的img標籤,但它一開始錯過<

<img ng-src="{{post.attachments.url}}" /> 
+0

我試過用ng-src,但是不能正常工作 – user3584779

+0

當你在inspect元素中檢查它時,你會在ng-src中綁定url嗎? –

+0

我不明白 – user3584779

-2

嘗試使用如下:

ng-src="{{post.attachments[0].url}}" 

而不是原來的src="{{post.attachments.url}}"see documentation)。