'angular.js'에 해당되는 글 1건

  1. 2015.07.29 angular, http로 json가져오기.





Curran의 20번 exam:

- $http 서비스를 이용해 json을 웹으로 가져오기.

<html ng-app="countryApp">

<head>

<meta charset="utf-8">
<title>Angular.js Example</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script>
<script>
var countryApp = angular.module('countryApp', []);
countryApp.controller('CountryCtrl', function ($scope, $http){

$http.get('countries.json').success(function(data) {

$scope.countries = data;
});
});
</script>
</head>
<body ng-controller="CountryCtrl">
<table>
<tr>
<th>Country</th>
<th>Population</th>
</tr>
<tr ng-repeat="country in countries">
<td>{{country.name}}</td>
<td>{{country.population}}</td>
</tr>
</table>
</body>
</html>


Posted by yongary
,