使用AngularJS和wordpress从JSON响应中获取图像URL

时间:2014-04-29 10:55:24

标签: javascript jquery html json angularjs

我正在尝试使用angularjs从json API获取图像。 我正在使用html文件来获取图像,但我想我错过了一些东西,它不起作用。 这是我的HTML:

<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 个答案:

答案 0 :(得分:2)

使用ng-src并注意您的img标记,它确实错过了&lt;在开头

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

答案 1 :(得分:-2)

尝试使用以下内容:

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

而非原始src="{{post.attachments.url}}"see documentation)。