I am currently experimenting with promises and AngularJS.
While my backend is returning the correct values, I am facing an issue where my HTML view does not display the table with the data from the backend.
What could be causing this problem?
Here is the snippet of my HTML code:
<div ng-app="clinang" ng-controller="pacientesCtrl">
<a class='btn btnprimary' href='/getdadospac/?oper=S' >Button</a>
<table ng-table="tableParams" class="table" show-filter="true">
<tr ng-repeat="paciente in $data">
<td title="'Pront'" filter="{ name: 'text'}" sortable="'pront'">
{{paciente.pront}}</td>
<td title="'Nome'" filter="{ age: 'number'}" sortable="'nome'">
{{paciente.nome}}</td>
</tr>
</table>
</div>
Below is a sample of the JSON data returned by the backend:
{"draw":1,"recordsTotal":5303,"recordsFiltered":5303,
"data":[{"DT_RowId":"4367","pront":"4367","nome":"XXXXXXXXX","endereco":"RUA TEODORO DA SILVA,294\/314","bairro":"VILA ISABEL","cidade":"RIO DE JANEIRO","estado":"RJ","telefone":"2567*0440","cpf":"","email":""},
{"DT_RowId":"21","pront":"21","nome":"YYYYYYYYY","endereco":"R ARAGUAIA","bairro":"PARQUE CHUNO","cidade":"DUQUE DE CAXIAS","estado":"RJ","telefone":"35637685","cpf":"02570293709","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e2888381878c8ba28b85cc818d8fcc8090">[email protected]</a>"},
{"DT_RowId":"23","pront":"23","nome":"ZZZZZZZZZZ","endereco":"rua 18 de outubro 241 101","bairro":"tijuca","cidade":"RIO DE JANEIRO","estado":"RJ","telefone":"","cpf":"","email":""},
... (continued data) ...
{"DT_RowId":"31","pront":"31","nome":"JOAO SDAFSA SOUZA","endereco":"av dom helder camara 312 bl 05 apt 102","bairro":"benfica","cidade":"RIO DE JANEIRO","estado":"RJ","telefone":"","cpf":"075422437-64","email":""},
{"DT_RowId":"33","pront":"33","nome":"SKDJFSDAJFLASD","endereco":"fabio da luz 275 bl 04 apt 504","bairro":"meier","cidade":"RIO DE JANEIRO","estado":"RJ","telefone":"3979-0859","cpf":"","email":""}]}
JavaScript Code Snippet:
var app = angular.module("clinang", ["ngTable", "ngResource"]);
(function() {
app.controller("pacientesCtrl", pacientesCtrl);
pacientesCtrl.$inject = ["NgTableParams", "$resource"];
function pacientesCtrl(NgTableParams, $resource) {
// Uncomment the next line to debug using Chrome Dev Tools
debugger;
var Api = $resource("/getdadospac/?oper=S");
this.tableParams = new NgTableParams({}, {
getData: function(params) {
// Making an AJAX request to API
return Api.get(params.url())
.$promise
.then(function(rows) {
params.total(rows.recordsTotal); // Re-calculating page navigation controls
return rows.data;
});
}
});
this.tableParams.reload();
}
})();