ANGULARJS provides $http control and can read data from the server as a service. The server can make a database call to fetch the records. ANGULARJS requires data in JSON format. Once the data is ready, $http can be used to get data from the server in the following way.
function Studentcontroller ($scope, $http) {
var url= "Data.txt";
$http. Get (URL). Success (function (response) {
$scope. Students = response;}
);
Here, the student records included in the Data.txt. $http Service enables Ajax to invoke and set properties for its students. The student model can be used to draw HTML tables.
Example
Data.txt
[
{
' name ': ' Mahesh Parashar ',
' rollno ': '
percentage ': ' 80% '
},
{
' name ': ' Dinkar Kad ",
" Rollno ": 201,
" percentage ":" 70% "
},
{
" Name ":" Robert ",
" Rollno ": 191, "
percentage": "75%"
},
{
"Name": "Julian Joe",
"Rollno": "Percentage": "
77%"
}
]
Testangularjs.html
<html>
<head>
<title>Angular JS Includes</title>
<style>
table, th , td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f2f2f2;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app="" ng-controller="studentController">
<table>
<tr>
<th>Name</th>
<th>Roll No</th>
<th>Percentage</th>
</tr>
<tr ng-repeat="student in students">
<td>{{ student.Name }}</td>
<td>{{ student.RollNo }}</td>
<td>{{ student.Percentage }}</td>
</tr>
</table>
</div>
<script>
function studentController($scope,$http) {
var url="data.txt";
$http.get(url).success( function(response) {
$scope.students = response;
});
}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
</body>
</html>
Output
To run this example, you need to deploy Textangularjs.html,data.txt to a network server. Open the Textangularjs.html request server in a Web browser using the URL. See the results as follows:
The above is ANGULARJS Ajax basic data collation, follow-up to continue to collate relevant information, thank you for your support of this site!