javascript - Angularjs issue $http.get not loading image -


i'm trying create ionic application uses gallery. i'm unsure why image isn't being loaded application.

what i'm trying develop gallery loads images json file.

here's html

<ion-view view-title="gallery" align-title="center">  <ion-content ng-controller="photoctrl" ng-init="getimages()">     <div class="row" ng-repeat="image in images" ng-if="$index % 4 === 0">         <div class="col col-25" ng-if="$index < images.length">             <img ng-src="{{data.images[$index].src}}" width="100%" />         </div>         <div class="col col-25" ng-if="$index + 1 < images.length">             <img ng-src="{{data.images[$index + 1].src}}" width="100%" />         </div>         <div class="col col-25" ng-if="$index + 2 < images.length">             <img ng-src="{{data.images[$index + 2].src}}" width="100%" />         </div>         <div class="col col-25" ng-if="$index + 3 < images.length">             <img ng-src="{{data.images[$index + 3].src}}" width="100%" />         </div>     </div> </ion-content> </ion-view> 

javascript:

.controller("photoctrl", function($scope, $http) {      $scope.images = [];      $scope.getimages = function() {         $http.get('https://api.myjson.com/bins/30vuu')             .success(function(data) {                 $scope.data = images;             })     }  }); 

i have created codepen: http://codepen.io/beefman/pen/enmgzg

the json api return associative array (key-value pair) this:

{"images":"http://mintywhite.com/wp-content/uploads/2012/10/fond-ecran-wallpaper-image-arriere-plan-hd-29-hd.jpg"} 

but template code expects array (list):

data.images[$index].src 

so start matching json format expected template.

edit: here's json format match template's expectations:

{'images': [{'src': 'url1'}, {'src': 'url2'}]} 

also, make sure set images variable in callback

$scope.images = data.images 

now $scope.images list of key value pairs

with ng-repeat can display images so:

<div ng-repeat="image in images">   <img ng-src="image.src" /> </div> 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -