2016-08-09 13 views
1

我正在使用AngularStrap的popover指令。我有一個物體的集合,被渲染爲切換。當點擊切換時,範圍上的數據不會被改變......我嘗試了很多不同的方法來做到這一點。陣列上的深度觀察不能在AngularJS數據綁定中工作

這是酥料餅

app.controller('CurvesPopoverCtrl', ['$scope', '$filter', 'AppData', 
    function($scope, $filter, AppData) { 
     'use strict'; 

     $scope.popoverCurrencies = AppData.getCurrencies(); 
     $scope.$watch ('popoverCurrencies', function(val) { 
      if(val !== null && val !== undefined){ // only fires when popover opens. 
       console.log("toggled", val); 
       //AppData.setCurrencies($scope.currencies); 
      } 
     }, true); // deep watch 


    } 
]); 

的控制器這是酥料餅的模板

<div class="well curves-popover" ng-controller="CurvesPopoverCtrl"> 
    <div class="row"> 
    <div ng-repeat="currency in popoverCurrencies"> 
     <div class="clearfix" ng-if="$index % 3 == 0"></div> 
     <div class="col-md-4"> 
     <div class="togglebutton"> 
      <label> 
      <span ng-class="currency.iconClass"></span> <span>{{currency.ccy}}</span> 
      <input type="checkbox" checked="currency.build"> 
      </label> 
     </div> 
     </div> 
    </div> 
    </div> 
</div> 

回答

1

它得到,當你試圖同時使用NG-觀看集合有點複雜重複。按照docs

每個模板實例都有它自己的範圍......

因此,當這些範圍內的值更新表不通知。一種解決方法是將一個單獨的控制器綁定到ng-repeat的每個迭代中,如here所示。但另一種更清晰的方法是利用ng-change指令來攔截這些值的更新。我解釋了一下here

+0

謝謝我最終這樣做了 rex