Ionic Framework web services loop $http json request
Web Services Loop $http json request |
Today Discussed Ionic Framework web Services data looping Concepts. Angularjs Previously discussed angularjs looping concepts same based ionic framework used. Angularjs and Ionic Framework is same concepts. Here follows this sample code in ionic framework and more information and example click here
controller('DataCtrl', function($scope, $http, data) { $scope.name = 'World'; $scope.allads = []; $scope.data= []; $http.get('http://www.mysite.com/list.json').success(function(data) { $scope.allads = data; $scope.loadMore(); }); var counter = 0; $scope.loadMore = function() { var data = []; var l = $scope.data.length; var m = Math.min(l+10, $scope.allads.length); for ( var i = l; i < m; i++) { data.push($scope.allads[i]); } console.log('Loading more!', m); $scope.ads = $scope.ads.concat(data); $scope.$broadcast('scroll.infiniteScrollComplete'); }; $scope.$on('stateChangeSuccess', function() { $scope.loadMore(); }); // THIS METHOD LOADS 4 LOCAL TEST ITEMS WITH THE ADSSERVICE //$scope.ads = ads; })
and.service('AdsService', function($q) { return { ads : [ { shortrelativetime:'30 min ago', title: 'TST อาหารเสริมเพี่มความสูง', group:'Vehicles', category:'Cars', province:'Vientiane Capital', district:'Xaythany', price:'24000', currency:'USD', photo:'20140202-040753-c1395444fd.jpg', id: 1 }, { shortrelativetime:'1 day ago', title: 'TST Samsung Galaxy Grand', group:'High Tech', category:'Phones', province:'Vientiane Capital', district:'Xaythany', price:'6000', currency:'THB', photo:'20140218-101800-1602504d17.jpg', id: 5 }, { shortrelativetime:'1 day ago', title: 'TST ຂາຍດິນປຸກສ້າງ', group:'Real Estate', category:'Land or House', province:'Vientiane Capital', district:'Xaythany', price:'850000', currency:'THB', photo:'20140715-080420-4a0ba40b89.jpg', id: 6 }, { shortrelativetime:'08 Jun 2014', title: 'TST HTC One', group:'High Tech', category:'Phones', province:'Vientiane Capital', district:'Xaythany', price:'12000', currency:'THB', photo:'20140604-083644-046276fe30.jpg', id: 9 } ], getAds: function() { return this.data }, getAd: function(adId) { var dfd = $q.defer() this.ads.forEach(function(ad) { if (ad.id === adId) dfd.resolve(ad) }) return dfd.promise } } })