Showing posts with label display json data in table using angularjs. Show all posts
Showing posts with label display json data in table using angularjs. Show all posts

Sunday, February 9, 2014

display json data in table using angularjs just check json format: { details:[{},{}] } object array object:

html:
<!doctype html>
<html lang="en" >
<head>
<title>Page Title</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script>
var app = angular.module('myApp', []);

app.controller('MyCtrl', function($scope,$http) {

 $http.get('js/jsondataexample4json.json').success(function (data) {
  $scope.myData = data.results;
 });

});
</script>
</head>
<body>
<div  ng-app="myApp" id="ng-app" ng-controller="MyCtrl">

<div ng-repeat="post in myData" >

<h2>
{{post.id}} - {{post.name}}<br/>
</h2>

</div>
  
</div>
</body>
</html>

json:

{
"results": [
    {
        "id": 1,
        "name": "Test"
    },
    {
        "id": 2,
        "name": "Beispiel"
    },
    {
        "id": 3,
        "name": "Sample"
    }
]

}

output:

1 - Test

2 - Beispiel

3 - Sample