Angularjs ng-repeat does not display data

Asked

Viewed 81 times

0

I made the request via get using the Laravel as backend. However, if I update some data in the database itself, I need to refresh the page where it is loaded angular for it to update. Using the angle, it would not have to update automatically?

<!DOCTYPE html>
<html ng-app="myApp">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>


<div ng-controller="myCtrl">
<table>
    <tr ng-repeat="t in teste">
        <td>{{t.id}}</td>
        <td>{{t.total}}</td>
    </tr>
</table>    
</div>


<script>


var app = angular.module('myApp', []);

app.controller('myCtrl', function($scope, $http) {
  $http.get("//localhost:8000/angular")
  .then(function(response) {        
      $scope.teste = response.data;
      console.log($scope.teste);



  });
});
</script>

</body>
</html>
  • What comes out here? console.log($scope.teste);

  • The request exits via get normal. (4) [{... }, {...}, {...}, {...}] 0 : {id: 1, quantity_products: 2, total: 3, created_at: null, updated_at: null, ... } 1 : {id: 2, quantity_products: 3, total: 55, created_at: null, updated_at: null, ... } 2 : {id: 3, quantity_products: 4, total: 50, created_at: null, updated_at: null, ... } 3 : {id: 4, quantity_products: 5, total: 60, created_at: null, updated_at: null, ... } length : 4 ;proto : Array(0

  • I can display in {{t. id}} and t.{{total}}, but if I update the data in the database, it doesn’t update in the view. You have to give F5

  • This is because you are not making requests at intervals, you are only making the request when opening for the first time, so if you want to update, use setInterval.

  • But shouldn’t he work asynchronously with my backend? I don’t understand..

  • Asynchronous is not reactive. Maybe you’re confusing the two concepts? Reactivity in Angularjs (and other js reactive frameworks) is limited to the front-end.

  • Yes, I get it. Thank you.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.