1
votes

Im loading data from php to a variable in angular js but the table dosent load the data and remains empty

       <script>
           var app = angular.module('clientesApp', []);
               app.controller('clientesController', function ($scope,$interval) {
               $scope.clientes =[];
               $scope.error = [];
               $scope.alertMsg=false;
               $scope.carregarClientes = function () {
                   $.getJSON(
                       "/abcaia/getclientes.php", {},
                       function (jsonData) {
                           $scope.clientes = jsonData;
                           console.log($scope.clientes);
                           $scope.applay;
                       });

               };



         });
       </script>

I added a button that calls the function of requesting data and the data loads after that, but i whant for it to load when the page loads

       <div ng-init="carregarClientes()">
         <button id="btnEnviaComent" class="btn btn-success btn-x" ng-click="carregarClientes()">
             Enviar
         </button>
         <table class="table table-bordered table-striped">
             <thead>
               <tr>
                 <th>id</th>
                 <th>info</th>
               </tr>
             </thead>
             <tbody ng-repeat = "c in clientes" >
               <td>{{c.idCliente}}</td>
               <td>{{c.info}}</td>
             </tbody>
         </table>
       </div>
2

2 Answers

0
votes

Just invoke $scope.carregarClientes() after the function declaration. You will get the same results as clicking the button.

0
votes

Found the problem

i had $scope.apply; insted of $scope.$apply();