Created
March 13, 2013 11:33
-
-
Save mrosati84/5151276 to your computer and use it in GitHub Desktop.
An Angular.js example for making XHR calls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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