Refresh ng-repeat when receiving values from Firebase realtime database

0

Hello! I'm learning Angularjs now, but I'm already an experienced Android programmer.

I get the data from the firebase correctly, but the ng-repeat does not update when the array is changed. If I click on some other field it updates ...

javascript that receives data from firebase .

$scope.notas = [ ];

var retrieveNotas = function () {
    firebase.database().ref("notas").on('value', function(snapshot) {
        snapshot.forEach(function (child) {
            $scope.notas.push(child.val());
        });
        console.log($scope.notas)
    });
};

table with ng-repeat

<table class="table">
    <tr class="tdAlign" ng-show="notas.length > 0">
        <th></th>
        <th>Nome</th>
        <th>Data</th>
        <th>Cliente</th>
        <th>Valor</th>
    </tr>
    <tr class="tdAlign" ng-class="{selecionado: nota.selecionado}" ng-repeat="nota in notas | filter:busca">
        <td><input type="checkbox" ng-model="nota.selecionado"></td>
        <td>{{nota.nome | uppercase}}</td>
        <td>{{nota.data}}</td>
        <td>{{nota.cliente.fantasia}}</td>
        <td>{{nota.valor | currency}}</td>
    </tr>
</table>
    
asked by anonymous 07.09.2017 / 01:29

1 answer

0

To update the note array, you will need to run the $ apply Angle function.

$scope.$apply(function () {
  $scope.notas.push(child.val());
});
    
11.09.2017 / 05:42