Unable to see WordPress posts


#1

I am working in a app where I am displaying the posts of a WordPress account. When test the app in the browser everything works fine, I have my app for now in a DIVSHOT, but when I open the app in my mobile browser, I can’t see non post.

Here is my code

.service('FreshlyPressed', function($http, $q) {
  return {

    getBlogs: function($scope) {
      var posts = [];
      $http.get('http://urbanetradio.com/wp-json/posts')
        .success(function(result) {
          $scope.posts = result;
        })
    },

    getPostById: function(postId) {
      var url ='http://urbanetradio.com/wp-json/posts/'+ postId;
      return $http.get(url);
    }

  }

});

the controller

.controller('NewsCtrl', function($scope, $ionicLoading, FreshlyPressed) {

  $scope.posts = [];

  $scope.doRefresh = function() {
    $scope.posts = FreshlyPressed.getBlogs($scope);
    $scope.$broadcast('scroll.refreshComplete');
  };
  $scope.doRefresh();

});

Here is the app so you can see what I talk about http://development.urbanetradio.divshot.io/#/, try testing it in a desktop and then in your mobile.

so what is going on ?


#2

I’m using this right inside my controller to load content from WordPress. Obviously you’d need to wrap it in a function.

$scope.postsURL = 'http://yourdomain.com/wp-json/posts?_jsonp=JSON_CALLBACK';
$http.jsonp($scope.postsURL).success(function(data, status, headers, config) {
    $scope.posts = data;
}).
error(function(data, status_headers, config) {
    console.log('error');
});

#3

I was missing the params status, headers, config, I have it working now, thanks :smile:


#4

All you need to use is https://www.npmjs.com/package/wp-api-angularjs