Curriculum
Course: AngularJS
Login

Curriculum

AngularJS

AngularJS Tutorial

0/65
Text lesson

JSON

The response data is expected in JSON format, ideal for data transmission and easy to handle in AngularJS or any JavaScript environment.

For example, the server returns a JSON object with 15 customers in an array called records.

Example

The ng-repeat directive is ideal for iterating over an array.

<div ng-app=”myApp” ng-controller=”customersCtrl”>

<ul>
  <li ng-repeat=”x in myData”>
    {{ x.Name + ‘, ‘ + x.Country }}
  </li>
</ul>

</div>

<script>

var app = angular.module(‘myApp’, []);
app.controller(‘customersCtrl’function($scope, $http) {
  $http.get(“customers.php”).then(function(response) {
    $scope.myData = response.data.records;
  });
});
</script>

Application Overview:

The customersCtrl controller includes $scope and $http objects, with $http acting as an XMLHttpRequest for fetching external data.

The $http.get() method retrieves JSON data from https://www.code7school.com/angular/customers.php, and on success, the controller assigns the data to a $scope property called myData.