【发布时间】: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>
【问题讨论】: