routeparams不工作在ng-repeat NO RESPONSE

时间:2014-05-16 15:08:19

标签: javascript angularjs angularjs-ng-repeat directive ngroute

我正在开发一个shoppingCart项目,并且想要动态地将数据导入到视图中,所以我在template.html中调用routeParams但是它通常在检查时到达,但它不能与ng-repeat一起使用。

的index.html

<a style="cursor: pointer;" ng-href="#/store/{{something.name}}/{{ child.name }}">{{ child.display_name }}</a>

    app.js中的路由


    when('/store/:Department/:Category', {
        templateUrl: 'partials/template.html',
        controller: storeController
    }).

controller.js


function storeController($scope, $route, $routeParams, $location, DataService) {

    $scope.name = "storeController";
    $scope.$route = $route;
    $scope.$location = $location;
    $scope.$routeParams = $routeParams;
    $scope.Category = $routeParams.Category;
}

store.js

function store() {
    this.fruits = [
        new product("APL", "Apple", "Eat one every day to keep the doctor away!", 12, 90, 0, 2, 0),
        new product("BAN", "Banana", "These are rich in Potassium and easy to peel.", 4, 120, 0, 2, 1)];
}

template.html

        

<pre>$routeParams.Category = {{$routeParams.Category}}</pre>

我真的需要这个工作,否则我必须像store.fruits,store.vegetables一样调用它,并且必须为每个文件制作单独的文件。请帮助

1 个答案:

答案 0 :(得分:0)

你缺少的是这一行

<li class="col-sm-6 col-md-3 animate" ng-repeat="product in store.{{$routeParams.Category}} | orderBy:'name' | filter:search">

将其更改为此

<li class="col-sm-6 col-md-3 animate" ng-repeat="product in store[$routeParams.Category] | orderBy:'name' | filter:search">