2016-02-08 86 views
0

我想從JSON中檢索圖像。現在我正在從JSON中檢索所有這些東西,如價格,顯示順序但圖像無法檢索。在Mobile Angular Ui中沒有從JSON中檢索圖像(Angular Js)

HTML:

<div ng-controller="chooseProductDescription"> 
       <div ng-repeat="cat in productDescription"> 
         <img src="{{cat.product.productPictures[0].pictureUrl}}"> 
         <span>Price</span>{{cat.product.price}} 
         <span>Display Order</span>{{cat.product.productPictures[0].displayOrder}} 
       </div> 
      </div> 

控制器:

.controller('chooseProductDescription', function($scope, $http){ 
    $http({ 
     method:'get', 
     url:'http://www.json-generator.com/api/json/get/cgrvadFrGW?indent=2', 
     header:{'Content-Type':'application/json'}, 
    }).success(function(data,status,headers, config){ 
     $scope.productDescription = data; 
     alert("shjkshjksadhkjas"); 
    }).error(function(data, status,headers, config){ 

    }) 
}) 

現在我從這個網址檢索數據:

http://www.json-generator.com/api/json/get/cgrvadFrGW?indent=2

我想從json中檢索圖像。請分享你的想法。

回答

1

您在$ http承諾的迴應中沒有使用正確的格式。代碼應該是:

$http({ 
    method:'get', 
    url:'http://www.json-generator.com/api/json/get/cgrvadFrGW?indent=2', 
    header:{'Content-Type':'application/json'}, 
}).success(function(response){ 
    $scope.productDescription = response.data; 
    alert("shjkshjksadhkjas"); 
}).error(function(response){ 

}) 
+0

是的,我嘗試過。但它不是行得通的。 –

+0

也許你正在使用$ http承諾錯誤的響應結構。規範正在描述一個具有數據屬性的響應對象。您應該嘗試:''http http://www.json-generator.com/api/json/get/cgrvadFrGW?index=2', header:{'http://'http://www.json-generator.com/api/json/get/cgrvadFrGW?indent = {'Content-Type':'application/json'} })。 (回覆){ })''' – alpha1554

+0

謝謝保存我的時間。如果你喜歡我的問題,那麼投票支持其他人。 –