【问题标题】:routeparams not working in ng-repeat NO RESPONSErouteparams 在 ng-repeat NO RESPONSE 中不起作用
【发布时间】:2014-05-16 15:08:18
【问题描述】:

我正在处理一个 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.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 一样调用它,并且还必须为每个文件创建单独的文件。请帮忙

【问题讨论】:

  • ng-repeat 代码在哪里?
  • 请看一下,我真的需要这个来理解为什么 ng-repeat 不接受 routeParams,这可能是一个错误还是有其他方法?
  • ng-repeat="product in store[$routeParams.Category].....
  • 不 ...dint 工作..请帮助..有一秒钟我很兴奋,这就是我所缺少的,但又一次;(
  • 标签: javascript angularjs angularjs-ng-repeat directive ngroute


    【解决方案1】:

    你缺少的是这一行

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

    【讨论】:

      猜你喜欢
      相关资源
      最近更新 更多
      热门标签