- $http 서비스를 이용해 json을 웹으로 가져오기.
| ||
<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> |