我正在尝试使用 ionic(angular) 应用程序中的 wp-rest-api v2 从 wordpress 站点加载每个帖子,然后将此列表中的每个帖子链接到所需的帖子和页面,问题是未显示帖子 ID,所以如果我将鼠标悬停在posts.html中的任何帖子上我只看到#/app/posts/的链接而不是例如#/app/posts/4821(它是示例帖子的ID)
// in App.js I have the route for this pages
.state('app.posts', {
url: '/posts',
data : { auth : true },
cache : false,
views: {
'menuContent': {
templateUrl: 'templates/posts.html',
controller : 'PostsCtrl'
}
}
})
.state('app.postDetails', {
url: "/postDetail/:postId",
views: {
'menuContent': {
templateUrl: 'templates/postDetail.html',
controller : 'postDetailCtrl'
}
}
})
//in controller.js I have the PostsCtrl
.controller('postDetailCtrl', function($scope, $http, $stateParams, $sce) {
$http.get('http://example.com/wp-json/wp/v2/posts/' + $stateParams.postId).then(
function(returnedData){
$scope.postDetails = returnedData.data;
console.log($scope.postDetails);
$scope.post_title = $sce.trustAsHtml($scope.postDetails.title.rendered);
$scope.post_content = $sce.trustAsHtml($scope.postDetails.content.rendered);
}, function(err){
console.log(err);
})
})
<!--This will load all the posts in posts.html template -->
<ion-item class="item item-avatar item-text-wrap" ng-repeat="recentPost in recentPosts | filter: searchText" href="#/app/posts/{{post.ID}}">
</ion-item>
<!-- this is the postDetails.html, template for each post-->
<div class="item item-avatar">
<div class="text-right item-text-wrap" ng-bind-html="post_title"></div>
</div>
<div class="item item-image">
<img ng-src="{{post_image}}">
</div>
<div class="item" dir="rtl">
<p class="text-right item-text-wrap" ng-bind-html="post_content"></p>
</div>