Tuesday, January 30, 2018

How to write a program for JSON in angularJS.

  • The data you get from the response is expected to be in JSON format.
  • JSON is a great way of transporting data, and it is easy to use within AngularJS, or any other JavaScript.

Program

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js">
</script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl"> 
<table border="1">
  <tr ng-repeat="x in myData">
    <td> {{ x.Name }}
    </td>
    <td> {{ x.Country }}
    </td>
  </tr>
</table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) 
{
  $http.get("https://www.w3schools.com/angular/customers.php").then(function (response) 
  {
    $scope.myData = response.data.records;
  });
});
</script>
</body>
</html>

Output



0 comments:

Post a Comment

Thanks For Commented.

TechTalk