Skip to content

Instantly share code, notes, and snippets.

@mrosati84
Created March 13, 2013 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrosati84/5151276 to your computer and use it in GitHub Desktop.
Save mrosati84/5151276 to your computer and use it in GitHub Desktop.
An Angular.js example for making XHR calls
---
The html file "index.html"
---
<!DOCTYPE html>
<html ng-app>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.1/angular.min.js"></script>
<script type="text/javascript" src="controllers.js"></script>
</head>
<body>
<div ng-controller="JsonController">
<ul ng-repeat="persona in persone">
<li>{{ persona.nome }}</li>
</ul>
</div>
</body>
</html>
---
The Angular controller "controllers.js"
---
function JsonController ($scope, $http) {
$http({
url: 'persone.json',
method: 'GET'
}).success(function(data, status, headers, config) {
$scope.persone = data;
});
}
---
The JSON file "persone.json"
---
[
{
"nome": "Matteo"
},
{
"nome": "Maurizio"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment