Thursday, September 3, 2015

Angular http

                     Using angular for http 

  Using angular it is simple to get JSON data and display it in a view.

Edit in plunker

HTML



<html ng-app="myApp">
<head><script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<meta charset="utf-8" />
</head>
<body >
      <div ng-controller="customersCtrl">
            <h1>http get using angular</h1>
            <ul>
                <li ng-repeat="x in names">
                    {{'Name:   ' + x.Name + ',     Country:   ' + x.Country }}
                </li>
            </ul>
        </div>
  <script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
        $http.get("http://www.w3schools.com/angular/customers.php")
            .success(function(response) {
                $scope.names = response.records;
            });
    });
  </script>
</body>
</html>

Output

No comments:

Post a Comment