2015-01-06 33 views
0

可以将routeparam设置为过滤器中使用的变量?我不相信我有正确的格式。我沿着URL传递它,但似乎无法正确使用它。我需要这个工作,因为我似乎无法得到核心REST调用过滤为规定的位置:Filter AngularJS REST JSON Data: error:badcfg Response does not match configured parameter

例子:

控制器:

pfcControllers.controller('pfcCategoriesCtrl', ['$scope', '$routeParams', 'pfcArticleCategories', function ($scope, $routeParams, pfcArticleCategories) { 
    $scope.category = pfcArticleCategories.query(); 
    $scope.articlecategoryID = { articlecategoryID: $routeParams.articlecategoryID }; 
}]); 

筛选:

<table class="table table-striped"> 
     <tr> 
      <th>ID</th> 
      <th>Title</th> 
      <th>Category ID</th> 
      <th>Link</th> 
     </tr> 
     <tr ng-repeat="articles in category | filter:{articlecategoryid:'articlecategoryID'} | orderBy:articleSortOrder"> 
      <td>{{articles.id}}</td> 
      <td>{{articles.articletitle}}</td> 
      <td>{{articles.articlecategoryid}}</td> 
      <td><a ng-href="#article/{{article.id}}/{{article.articletitle}}">{{article.articletitle}}</a></td> 
     </tr> 
    </table> 

从另一页面链接:

<a ng-href="#categories/1">Category 1</a> 

App.JS路线:

when('/categories/:articlecategoryID', { templateUrl: './views/categories.html', controller: 'pfcCategoriesCtrl' }). 

回答

1

我想这可能工作。

pfcControllers.controller('pfcCategoriesCtrl', ['$scope', '$routeParams', 'pfcArticleCategories', function ($scope, $routeParams, pfcArticleCategories) { 
    $scope.category = pfcArticleCategories.query(); 
    $scope.articlecategoryID = $routeParams.articlecategoryID; 
}]); 

各地articlecategoryID

<tr ng-repeat="articles in category | filter:{ articlecategoryid: articlecategoryID } | orderBy:articleSortOrder"> 
+0

没有这样的运气删除引号。如果我硬编码它(例如,articlecategoryid:1)它可以工作,但它似乎并不尊重routeparam – Kode