0

I'm trying to make a table footer auto-update but the ng-repeat and even the regular double-braces does not appear to auto-bind when the $scope value is updated.

https://jsfiddle.net/r0pk793e/3/

Specifically, I'm setting the value $scope.hello and incrementing it when the table updates (when the user changes a value in the table cells). Though I can see the value changes, it does not get re-bound to the HTML.

I believe this table should be updated by the following function, but it is not...

  <table class="tg">
    <tr>
      <td class="tg-yw4l" ng-repeat="item in items">{{item}}</td>
    </tr>
  </table>

The $scope.hello does change, as illustrated by the console.log($scope.hello);

  var doUpdate = function () {
    var items = [];

    for (var c = 0; c < headings.length; c++) {
      if (typeof (hot.getDataAtCell(0, c)) == "number") {
        var levelTotal = 0;
        var i = 0;

        do {
          levelTotal += hot.getDataAtCell(i, c);
          i++;
        } while (hot.getDataAtCell(i, c) != null);

        items.push(levelTotal);
      }
      else
      {
        items.push(' ');
      }
    }

    $scope.items = items;
    $scope.hello = $scope.hello + 1;
    console.log($scope.hello);
  }
2
  • your $scope.hello indeed changes if you see in console, but its not rendering into html Commented Feb 21, 2017 at 11:36
  • Because your doUpdate function is not attached to $scope so angular is not aware of that change, hence it is not updated, here is the modified code jsfiddle.net/r0pk793e/8 Commented Feb 21, 2017 at 12:00

1 Answer 1

2

When I tested your fiddle everything got updated

enter image description here

anyway if this still not working call $scope.$apply(); after updating your values and you will see the magic happening.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, yes, thank you - $apply() was needed. I think because the update is happening within the handsontable event listener. The update time I'm actually looking for is when the table content is changed by the user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.