Reputation: 95
I am new to Angular js and i wanted to pass one static json file through ajax and i am giving the codes below.How to Display the data of json file into the index file that i dont know. As i am new to angularjs please help me with these
Index.php
<body ng-app="Mymodule">
<div ng-controller="recordscontroller">
<table style="width:500px; border:solid 2px #CCC;">
<thead>
<tr style="text-align:left;">
<th>First Name</th>
<th>Last Name</th>
<th>Gender</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="emp in employee | orderBy : '-salary'">
<td>{{ emp.firstname }}</td>
<td>{{ emp.lastname }}</td>
<td>{{ emp.gender }}</td>
<td>{{ emp.salary | currency: 'Rs' }}</td>
</tr>
</tbody>
</table>
</div> <br>
</body>
Script.js
var app = angular.module("Mymodule",[]);
app.controller("recordscontroller", function($scope, $http){
var url = "data/records.json";
$http.get(url).success(function (response){
$scope.employee = response;
});
});
records.json
[
{
"firstname":"Kishan",
"lastname":"Dalsania",
"gender":"Male",
"salary":15000
},
{
"firstname":"Dipesh",
"lastname":"Mungara",
"gender":"Male",
"salary":20000
},
{
"firstname":"Roshan",
"lastname":"Trivedi",
"gender":"Male",
"salary":25000
},
{
"firstname":"Jay",
"lastname":"Dalsania",
"gender":"Male",
"salary":30000
},
]
Upvotes: 1
Views: 225
Reputation: 2295
Your JSON is not valid JSON.
If you check this version
https://jsfiddle.net/Mephiztopheles/qwd0y1pa
and this
https://jsfiddle.net/Mephiztopheles/qwd0y1pa/1/
JSON.parse('[{"firstname":"Kishan", "lastname":"Dalsania","gender":"Male","salary":15000},{ "firstname":"Dipesh", "lastname":"Mungara", "gender":"Male","salary":20000},{ "firstname":"Roshan", "lastname":"Trivedi", "gender":"Male", "salary":25000 }, { "firstname":"Jay", "lastname":"Dalsania", "gender":"Male", "salary":30000},]')
you will see
Upvotes: 1