【问题标题】:Table dosent load data using ng-repeat表不使用 ng-repeat 加载数据
【发布时间】:2020-10-17 05:17:52
【问题描述】:

我正在将数据从 php 加载到 angular js 中的变量中,但表格会加载数据并保持为空

 
           var app = angular.module('clientesApp', []);
               app.controller('clientesController', function ($scope,$interval) {
               $scope.clientes =[];
               $scope.error = [];
               $scope.alertMsg=假;
               $scope.carregarClientes = 函数 () {
                   $.getJSON(
                       "/abcaia/getclientes.php", {},
                       函数(jsonData){
                           $scope.clientes = jsonData;
                           控制台.log($scope.clientes);
                           $scope.app;
                       });

               };



         });
       脚本>

我添加了一个按钮,调用请求数据的功能,然后数据加载,但我希望它在页面加载时加载

       <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>

【问题讨论】:

    标签: php html angularjs


    【解决方案1】:

    只需在函数声明之后调用$scope.carregarClientes()。您将获得与单击按钮相同的结果。

    【讨论】:

    • 我已经尝试过这样做但它仍然没有加载表,我还在我的函数中添加了一个 ng-init 但仍然没有结果,thnx 无论如何
    • 删除ng-init,我建议你避免在你的模板中加入逻辑。这使得调试它变得更加困难。另一个建议是使用组件基础设计。你在浏览器上调试过吗?
    【解决方案2】:

    发现问题

    我有 $scope.apply; $scope.$apply();

    【讨论】:

      猜你喜欢
      • 2014-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-05
      • 1970-01-01
      相关资源
      最近更新 更多