ng-repeat's element not updated on array modification

前端 未结 3 1620
既然无缘
既然无缘 2020-12-31 15:12

When I trying to update my array on ng-click in order to update my ng-repeat\'s directive items:

  • 3条回答
    •  温柔的废话
      2020-12-31 15:24

      Without seeing more of your controller code, it is difficult to determine what the problem might be. Here is a simplified working fiddle. I suggest you compare it to what you have.

      Note that you don't need to call $scope.$apply() because the ng-click directive will do that for us automatically.

      HTML:

      • {{itemL1.name}}

      JavaScript:

      function MyCtrl($scope) {
          $scope.mainMenuL1Arr = [ {name: 'one'}, {name: 'two'} ];
          $scope.mainMenuL2Obj = { 
              one: [ {name: '1.1'}, {name: '1.2'} ],
              two: [ {name: '2.1'}, {name: '2.2'} ] };
          $scope.mainMenuL2CurArr = $scope.mainMenuL2Obj['one'];
          $scope.selectL2menu = function (itemL1name) {
              console.log(itemL1name);
              $scope.mainMenuL2CurArr = $scope.mainMenuL2Obj[itemL1name];
          };
      }
      

    提交回复
    热议问题