Android 如何列出特定类别的帖子[ionic&;angularjs]

Android 如何列出特定类别的帖子[ionic&;angularjs],android,angularjs,wordpress,ionic-framework,ionic,Android,Angularjs,Wordpress,Ionic Framework,Ionic,我正在使用wordpress json api、ionic和angularjs创建一个混合android应用程序。 我只被一件事困住了:我无法列出特定类别中的帖子。我得到了类别列表,但无法传递一些参数。 这是密码 controller.js .controller('CatsCtrl', function($scope, $http) { // You can change this url to experiment with other endpoints var categori

我正在使用wordpress json api、ionic和angularjs创建一个混合android应用程序。 我只被一件事困住了:我无法列出特定类别中的帖子。我得到了类别列表,但无法传递一些参数。 这是密码

controller.js

.controller('CatsCtrl', function($scope, $http) {

  // You can change this url to experiment with other endpoints
  var categoriesApi = 'http://shayarihunt.com/wp-    json/taxonomies/category/terms?_jsonp=JSON_CALLBACK';

  // This should go in a service so we can reuse it
   $http.jsonp( categoriesApi, {cache:true} ).
    success(function(data, status, headers, config) {
      $scope.categories = data;
     console.log( data );
     }).
    error(function(data, status, headers, config) {
  console.log( 'Post load error.' );
 });

})

.controller('CatsPostsCtrl', function($scope, $http) {

  // You can change this url to experiment with other endpoints
   var postsApi = 'http://shayarihunt.com/wp-json/posts?filter[cat]=' + the parameter has to come here, (I dont know what!!!) + '&_jsonp=JSON_CALLBACK';

  // This should go in a service so we can reuse it
    $http.jsonp( postsApi, {cache:true} ).
  success(function(data, status, headers, config) {
  $scope.posts = data;
  console.log( data );
   }).
    error(function(data, status, headers, config) {
      console.log( 'Post load error.' );
    });

   })
CatsCtrl显示所有类别,但CatsPostsCtrl应显示其未显示的类别中的所有帖子。 感谢您的帮助。
谢谢

您正在从
ui路由器
中查找
$stateParams
。有关更多详细信息,请查看

下面是一个演示用法。单击第二个图标以显示类别
印地语shayari
中的帖子。您也可以在中找到相同的代码

angular.module('demoApp',['ionic']))
.config(函数($stateProvider,$urlRouterProvider){
$stateProvider
.州(“家”{
url:“/”,
观点:{
主页:{
templateUrl:'home.html',
控制器:“CatsCtrl”
}
}
})
.州(“类别”{
url:“/category/:slug”,
观点:{
类别:{
templateUrl:'category.html',
控制器:“CatsPostsCtrl”
}
}
});
$urlRouterProvider。否则('/');
})
.controller('CatsCtrl',函数($scope,$http){
//您可以更改此url以试验其他端点
分类变量http://shayarihunt.com/wp-json/posts?_jsonp=JSON_CALLBACK';
//这应该放在服务中,以便我们可以重用它
$http.jsonp(categoriesApi,{cache:true})。
成功(函数(数据、状态、标题、配置){
$scope.posts=数据;
控制台日志(数据);
}).
错误(函数(数据、状态、标题、配置){
日志(‘加载后错误’、状态、标题);
});
})
.controller('CatsPostsCtrl',函数($scope、$http、$stateparms){
console.log($stateparms);
//您可以更改此url以试验其他端点
var postsApihttp://shayarihunt.com/wp-json/posts?filter[category_name]='+$stateParams.slug+'&_jsonp=JSON_CALLBACK';
$scope.category=$stateParams.slug;
//这应该放在服务中,以便我们可以重用它
$http.jsonp(postsApi,{cache:true})。
成功(函数(数据、状态、标题、配置){
$scope.posts=数据;
控制台日志(数据);
}).
错误(函数(数据、状态、标题、配置){
日志('加载后错误');
});
})


谢谢您的回答@awolf。但是我想显示我可以使用{{category.name}和控制器中的类别url来访问的类别列表。然后,当用户单击类别时,它应该使用{{post.title}显示该类别中的帖子列表,这怎么可能呢?…非常感谢您的回答您有哪些类别?在json中很难看到它们。你能给我写2或3个你的分类吗?然后我可以在JSON中找到它们。好的,请看一下更新的fiddle。类别的链接列表已添加到主路线。非常感谢@awolf。你能让我知道要创建哪些文件,哪些文件将包含哪些代码吗。如果我给你带来麻烦,我很抱歉。提前谢谢!!!