I must bring all the records from my Database, and how can I go through the array that returns the query and list the records in an html table
I must bring all the records from my Database, and how can I go through the array that returns the query and list the records in an html table
Use the ngRepeat
directive that allows you to iterate over an array and display it in the view:
angular.module("app",[])
.controller("ctrl",function($scope, $http){
$scope.personas = [];
$scope.cargar = function(){
$http.get("https://jsonplaceholder.typicode.com/users")
.success(function(users){
$scope.personas = users;
})
}
});
table{
width:100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<button ng-click="cargar()" >Cargar</button>
<table>
<thead>
<tr>
<th>Nombre</th>
<th>Email</th>
<th>Sitio web</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="persona in personas">
<td>
{{persona.name}}
</td>
<td>
{{persona.email}}
</td>
<td>
{{persona.website}}
</td>
</tr>
</tbody>
</table>
</div>
You only need to specify which model will contain the data and the directive will load the data when the array is full.