Unable to display WordPress posts

I am trying to display the posts of a WordPress account in my app, I was having troubles because of Access-Allow-Control-Origin, I am getting this error

I am using Firebase as a backend

Read More

XMLHttpRequest cannot load http://www.EXAMPLE-DOMAIN.com/api/v2/users/sign_in. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100‘ is therefore not allowed access.

so ok, someone ask me to use jsonp instead of get, now I am using jsonp and the error gone, but I am unable to see the posts in my app, here I have this JSBin or this Plunker just in case you want to take a look.

here is my code

.config(function($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state('tabs', {
      url: "/tabs",
      abstract: true,
      templateUrl: "tabs.html"
    })
    .state('tabs.news', {
      url: "/news",
      views: {
        'tab-news': {
          templateUrl: "tab-news.html",
          controller: 'NewsCtrl'
        }
      }
    })
   $urlRouterProvider.otherwise("/tabs/news");
})

.controller('NewsCtrl', function($scope,
                                 FreshlyPressed) {
  $scope.posts = [];
  $scope.doRefresh = function() {
    $scope.posts = FreshlyPressed.getBlogs($scope);
    $scope.$broadcast('scroll.refreshComplete');
  }
  $scope.doRefresh();
})

.service('FreshlyPressed', function($http) {
  return {
    getBlogs: function($scope) {
      $http.jsonp('http://urbanetradio.com/wp-json/posts?callback=JSON_CALLBACK')
        .success(function(result) {
          console.log(result);
          $scope.posts = result;
        });
    }
  }
})

and here the HTML

<script id="tab-news.html" type="text/ng-template">
  <ion-view>
    <ion-content>
      <div ng-repeat="post in posts">
        <a ng-href="#/tabs/news/{{post.ID}}">
          <h2 ng-bind-html="post.title"></h2>
          <p>{{post.date | date}}</p>
        </a>
      </div>
    </ion-content>
  </ion-view>
</script>

here is the method I am using

Related posts

Leave a Reply