WP JSON缩略图

时间:2015-11-26 02:38:16

标签: angularjs ionic

我并不熟悉angularjs并需要一些帮助。我有一个控制器获取json数据,但我没有抓住特色图像,头像或缩略图。我非常感谢如何将json数据中的其他帖子类型添加到我的输出中的一些指导。这是我的控制器js:

angular.module('myreddit') 

.controller('PostsCtrl', function( $scope, $http, DataLoader,     $timeout, $ionicSlideBoxDelegate, $rootScope ) {

  $rootScope.url = 'http://genesis2media.com/mobile/wp-json/wp/v2/';

console.log('PostsCtrl');

$scope.loadPosts = function() {

  DataLoader.get( $rootScope.url + 'posts' ).then(function(response) {
    $scope.posts = response.data;
    console.log( response.data );
  }, function(response) {
    console.log('error', response);
  });

}

// Load posts on page load
$scope.loadPosts();

paged = 2;
$scope.moreItems = true;

// Load more (infinite scroll)
$scope.loadMore = function() {

  if( !$scope.moreItems ) {
    return;
  }

  var pg = paged++;

  $timeout(function() {

    DataLoader.get( $rootScope.url + 'posts' + '?page=' + pg ).then(function(response) {

      angular.forEach( response.data, function( value, key ) {
        $scope.posts.push(value);
      });

      if( response.data.length <= 0 ) {
        $scope.moreItems = false;
      }
    }, function(response) {
      $scope.moreItems = false;
      console.log('error');
    });

    $scope.$broadcast('scroll.infiniteScrollComplete');
    $scope.$broadcast('scroll.resize');

  }, 1000);

   }

   $scope.moreDataExists = function() {
     return $scope.moreItems;
   }

   // Pull to refresh
   $scope.doRefresh = function() {

     console.log('Refreshing!');
     $timeout( function() {

        $scope.loadPosts();

       //Stop the ion-refresher from spinning
       $scope.$broadcast('scroll.refreshComplete');

     }, 1000);

    };

})

.controller('PostCtrl', function($scope, $stateParams,     DataLoader, $ionicLoading, $rootScope, $sce ) {

   $ionicLoading.show({
      noBackdrop: true
    });

  var singlePostApi = $rootScope.url + 'posts/' +     $stateParams.postId;

  DataLoader.get( singlePostApi ).then(function(response) {
      $scope.post = response.data;
      // Don't strip post html
      $scope.content =     $sce.trustAsHtml(response.data.content.rendered);
      $ionicLoading.hide();
    }, function(response) {
      console.log('error', response);
    });

});

0 个答案:

没有答案