Redirect to another view by a post id, not working


#1

I am receiving an external object from WordPress, in one view I have the post.title, and if you click in that title you can go to another view and see te entire post.content.

So far, I can not see the entire post because I am getting a couple error, posts is undefined.

I made a Plunkr, CodePen and one JSBin for you to understand easier. If you use JSBin is better because you can use the console which is integrated there. All you have to do is click on the title of the post, and you are going to realize that can not go to the other view.

Here is the code regarding my issue, which is the same you will see in the online editors I post above

.state('tabs', {
  url: "/tabs",
  abstract: true,
  templateUrl: "tabs.html"
})
.state('tabs.news', {
  url: "/news",
  views: {
    'tab-news': {
      templateUrl: "tab-news.html",
      controller: 'NewsCtrl'
    }
  }
})
.state('tabs.post-detail', {
  url: '/news/:postId',
  views: {
    'tab-news': {
      templateUrl: 'tab-post-detail.html',
      controller: 'PostDetailCtrl'
    }
  }
})

the html for the main view, news

<a ng-href="#/tabs/news/{{post.ID}}">
   <h2 ng-bind-html="post.title"></h2>
   <p>{{post.date | date}}</p>
</a>

and here is the view where you can not enter yet, the view where are redirected after clicking in the title on the main view

<div>
  <h3>{{:: post.title}}</h3>
  <p>{{:: post.content}}</p>
</div>

now the controller for the main view

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

here the service

angular.module('urbanet.app.service', [])

.service('FreshlyPressed', function($http) {
  return {
    getBlogs: function($scope) {
      $scope.posts = [];
      $http.jsonp('https://public-api.wordpress.com/rest/v1.1/freshly-pressed?callback=JSON_CALLBACK')
        .success(function(result) {
          $scope.posts = result.posts;
        });
    },

    get: function(postId, $scope) {
      console.log(postId);
      console.log($scope.posts);
      for (var i = 0; i < $scope.posts.length; i++) {
        if ($scope.posts[i].id === parseInt(postId)) {
          return $scope.posts[i];
        }
      }
      return null;
    }
  }
})

and controller for the second view, the view of the entire post

.controller('PostDetailCtrl', function($scope, $stateParams, FreshlyPressed) {
  $scope.post = FreshlyPressed.get($stateParams.postId, $scope);
});