首页 文章

routeparams不工作在ng-repeat NO RESPONSE

提问于
浏览
-1

我正在开发一个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

    你缺少的是这一行

    <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">
    

相关问题