在ng-repeat过滤器中使用$ routeParams

时间:2015-07-13 16:39:26

标签: angularjs angularjs-ng-repeat

我尝试传递$routeParams值来过滤ng-repeat数据。这是我的控制器:

myApp.controller('BookCtrl', ['$scope', '$routeParams' function($scope, $routeParams) {
    $http.get('books.json').success(function(data) {
        $scope.books = data;
        $scope.slug = $routeParams.slug;
    });
}]);

我的HTML:

<div class="container" role="document" ng-repeat="book in books | filter:{slug: {{slug}}}">
    <p>{{book.title}}</p>
</div>

可以这样做吗?我尝试使用上面的代码,但返回了语法错误:

http://errors.angularjs.org/1.4.1/$parse/syntax?p0=

1 个答案:

答案 0 :(得分:0)

问题已解决:

<div class="container" role="document" ng-repeat="book in books | filter:{slug:  slug }">