2016-12-22 1 views
2

私はangle.jsを使ってこのJSON(1)をレンダリングしています1.6、タイトルと説明が読み込まれているようですが、イメージプロパティからurlを取得できません。現在、次のように表示されています。角でオブジェクトデータをレンダリングするときにJSONタグを取り除く

<img ng-src="{"original": "https://xxx-export.s3.amazonaws.com/images/products/2016/12/product_1003_2.jpg"}"> 

テンプレートでレンダリングするURLを取得するにはどうすればよいですか?

(1)これは私のJSONオブジェクトのためのリファレンスです:

var items = [ 
     { 
      "id": 61, 
      "title": "Title 1", 
      "description": "Desc", 

     "images": [ 
       { 
        "original": "https://xxx-export.s3.amazonaws.com/images/products/2016/12/product_1003_2.jpg" 
       }, 
       { 
        "original": "https://xxx-export.s3.amazonaws.com/images/products/2016/12/product_1003_5.jpg" 
       }, 
       { 
        "original": "https://xxx-export.s3.amazonaws.com/images/products/2016/12/product_1003_3.jpg" 
       } 

      ] 
]; 

(2)これはあなたが持っているデータは、私のテンプレートで

<div ng-repeat="item in Item"> 
    <img ng-src="{$item.images[0]$}" /> 
    <h4>{$item.title$}</h4> 
    <p> {$item.description$} </p> 
</div> 
+0

私はあなたが '' –

答えて

1

は、URLを含むオブジェクトのプロパティを、あなたのimagesコレクション内のオブジェクトを参照していない:で

<img ng-src="{$item.images[0]$}" /> 

交換してください。これを試してみてください:

<div ng-repeat="item in Item"> 
    <img ng-src="{$item.images[0].original$}" /> 
    <h4>{$item.title$}</h4> 
    <p>{$item.description$}</p> 
</div> 
1

を表示されている方法ですもう一度逆参照してください!あなたはitems[n].images[0]を得ています。これは{ "original": "... url..." }のようなものです。

そのオブジェクトからoriginalエントリを取得するだけです。

<img ng-src="{$item.images[0].original$}" /> 
関連する問題