AngularJS 코드
<!--
reference : http://www.jacopretorius.net/2013/04/using-ngresource-with-angularjs.html
reference : https://github.com/wprl/baucis/blob/master/examples/angular-example-resource.html
There are two ways to implement REST client
first one is using $http. It is more flexible but need more coding.
The other one is $resource. It is more efficient.
-->
<html ng-app='jsonGetApp'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular-resource.js"></script>
<script type="text/javascript">
var jsonGetApp = angular.module('jsonGetApp',['ngResource']);
jsonGetApp.controller("MsgCtrl",["$resource","$scope","$log",function($resource,$scope,$log){
$scope.$log=$log;
$scope.jsonmsg='';
var msgs = $resource('/msg','',{query:{method:'GET',isArray:false}});
$scope.sendJson = function(){
$log.info('sendJson has been called');
var result = msgs.query();
$log.info(result);
$scope.jsonmsg=result;
}
}]
);
</script>
</head>
<body>
<div ng-controller="MsgCtrl">
<textarea rows="5" style="width: 100%" ng-model="jsonmsg" ></textarea>
<button ng-click="sendJson();">Get JSON</button>
{{jsonmsg}}
</div>
</body>
</html>
'프로그래밍 > JavaScript' 카테고리의 다른 글
자바스크립트 스터디 노트 #1 (0) | 2014.06.18 |
---|---|
AngularJS - Service,Factory 그리고 Provider의 차이 (0) | 2014.01.17 |
Fiddler를 간단한 JSON 웹서버로 사용하기. (0) | 2014.01.17 |
AngularJS 개발 환경 준비하기 (0) | 2014.01.12 |
Structuring jQuery with Backbone.js (0) | 2014.01.08 |