javascript - Retrieving posts by id -


i receiving json object wordpress looks this

{         "id": 4164,         "title": "24 horas non-stop con marco carola",         "status": "publish",         "type": "post",         "author": {             "id": 11,             "username": "vilma quiros",             "registered": "2015-04-16t07:04:04+00:00",             "meta": {                 "links": {                     "self": "http://urbanetradio.com/wp-json/users/11",                     "archives": "http://urbanetradio.com/wp-json/users/11/posts"                 }             }         },         "content": "<p class=\"p2\"><a href=  

here service

.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);     }  }); 

and here controller

.controller('newsctrl', function($scope, freshlypressed) {    $scope.posts = [];    $scope.dorefresh = function() {     $scope.posts = freshlypressed.getblogs($scope);     $scope.$broadcast('scroll.refreshcomplete');   }   $scope.dorefresh();  }); 

and here want:

in view display title , date of posts, main view

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

when click in title should redirected entired post here, in secondary view

  <div class="item item-text-wrap item-image padding">     <div class="special-font" ng-bind-html="post.content"></div>   </div> 

the routes

//the route main view  .state('tabs.news', {     url: '/news',     views: {       'tab-news': {         templateurl: 'templates/tab-news.html',         controller: 'newsctrl'       }     }   })  //the route second view see entire post  .state('tabs.post-detail', {   url: '/news/:postid',   views: {     'tab-news': {       templateurl: 'templates/tab-post-detail.html',       controller: 'postdetailctrl'     }   } }) 

i error

get http://urbanetradio.com/wp-json/posts/postid 404 (not found)

i guess need change function

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

as per code postid parameter want replace in string should append value in string in code

you need call method

   freshlypressed.getpostbyid(1);//1 postid value  

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -