Data Binding Does Not Work After Calling Function

1

I have the following function:

$scope.calcularTotal = function(startDate, endDate){
    $scope.items = $filter('betweenDate')($scope.items, 'dataPagamento', startDate, endDate);
    console.log("testee: "+$scope.items)
    var total = 0;
    var glosa = 0;
    var lote = 0;
    angular.forEach($scope.items, function(item) {
      total += (item.totalLiquido);
      glosa +=(item.totalGlosa);
      lote +=(item.totalLote);
    });
    $scope.totalLiquido = total;
    $scope.totalGlosa = glosa;
    $scope.totalLote = lote;
    console.log("Total: "+$scope.total)
    $state.go('tabs.facts', {}, {reload: true});
  }

In this function I go through an Array and make the sum of the values. In the% of% that has at the end the total appears correctly. But when I try to do Data Binding on my page the values do not appear:

This is the page:

ion-view title="Totais" cache-view="false">
  <ion-content has-header="true" padding="true">
    <h3 style="text-align:center">Total</h3>
    <p style="margin-top:30px;font-weight:bold;color: #0066FF">Total Lote:    {{totalLote | currency}}</p>
    <p style="font-weight:bold;color: #990000">Total Glosa: {{totalGlosa | currency}}</p>
    <p style="font-weight:bold;color: #339900">Total Líquido: {{totalLiquido | currency}}</p>
  </br>
</br>
</br>
</br>
<p>
  <a class="button icon ion-home" href="#/tab/home" style="width:100%"> Home</a>
</p>
</ion-content>
</ion-view>

And this is the result:

How could you solve this problem?

    
asked by anonymous 03.11.2015 / 18:11

1 answer

1

Tips:

1) You have to understand Angle Digest cycle ;

2) You should call this function somewhere (you did not detail this in the question) either by clicking a button or as a code in the controller;

3) When you change scope variables within the function, these changes happened at a time after the initial digest in the view load, so you must warn the Keystone to re-scan the changes. Something like: if (!$scope.$$phase) $scope.$apply(); in the last line of your function.

    
24.11.2015 / 14:02