Angular.js过滤器无法正常工作

时间:2014-07-10 14:01:58

标签: angularjs angularjs-ng-repeat angular-routing

我正在尝试根据我的$ routeParams进行过滤,但一定是做错了。

我的控制器:

app.controller('servicesDetail', function ($scope, HC, $resource, $routeParams) { 

HC.API.query(function (results) {
    $scope.services = results;
});

$scope.json={};
json._id=$routeParams.id;

});

我的HTML /模板:

<div class="services" ng-repeat="service in services | filter: json">
        <article class="service group">
       <a href="/services/{{service.name }}"><h3><pre>{{service.name }}</pre> </h3></a> 
       <p>{{service.name}}</p>
       <a href="/services/{{service.name}}">more</a>
       </article>

    </div>

我的JSON:

{ "_id" : ObjectId("53bc3733b7bbbf77208dec65"), "name" : "this is from the client", "__v" : 0 }
{ "_id" : ObjectId("53bc37abb7bbbf77208dec66"), "name" : "new", "__v" : 0 }

我基本上只是尝试将页面从完整列表过滤到详细信息页面并使用$ routeParams进行过滤。

1 个答案:

答案 0 :(得分:0)

app.controller('servicesDetail', function ($scope, HC, $resource, $routeParams) { 

HC.API.query(function (results) {
    $scope.services = results;
});

$scope.json={};
//don't forget about $scope
$scope.json._id=$routeParams.id;

});
相关问题