Skip to content Skip to sidebar Skip to footer

Angular Watchgroup Not Consistently Picking Up Model Changes

I have a dynamic orderBy function I am using for a ng-repeat. I had help with this from another post. He created a plunker and it works great. however when I integrated with projec

Solution 1:

You forgot to clear the array in the $watchGroup callback function.

$scope.$watchGroup(['vm.orderOptions[0].value', 'vm.orderOptions[1].value', 'vm.orderOptions[2].value'], function() {

  vm.orderBy = []; // <=- clear/reset the array

  angular.forEach(vm.orderOptions, function(x) {
    if (x.value) {
      [].push.apply(vm.orderBy, x.fields)
    } 
  });
});

Post a Comment for "Angular Watchgroup Not Consistently Picking Up Model Changes"