-1

我正在处理一个 shoppingCart 项目并希望将数据动态地带入视图中,因此我在 template.html 中调用 routeParams 但它正常到达,如检查通过但它不适用于 ng-repeat。

索引.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',
        控制器:存储控制器
    })。

控制器.js

函数 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)];
}

模板.html

        

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

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

4

1 回答 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">
于 2014-05-17T07:06:54.440 回答