Thursday 8 January 2015

Retrieve remote data with http get using AngularJS

AngularJS

Using http get to retrieve data from remote URL which correspondingly send response which should be in json format.




<!DOCTYPE html>
<html>
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>    <script>
      angular.module('myApp',[])
        .controller('angController',function($scope,$http) {
      $http.get("http://www.w3schools.com/website/Customers_JSON.php")
      .success(function(response) {$scope.names = response;});
        }
);

    </script>
  </head>
  <body ng-app="myApp">
  <div ng-app="" ng-controller="angController">
  <table border=1>
    <tr ng-repeat="x in names">
      <td>{{ x.Name }}</td>
      <td>{{ x.Country }}</td>
    </tr>
  </table>
  </div> 
</body>
</html> 

Output of this is code is given below :


{{ x.Name }}{{ x.Country }}

No comments: