수

AngularJS AJAX - 행동 양식

· 2017-08-15 (화) 22:57:06 · 2216
AngularJS AJAX - 행동 양식

행동 양식

위의 예 .get는 $http 서비스 메소드를 사용합니다 .

.get 메소드는 $ http 서비스의 바로 가기 메소드입니다. 몇 가지 바로 가기 방법이 있습니다.

.delete()
.get()
.head()
.jsonp()
.patch()
.post()
.put()
위의 메서드는 모두 $ http 서비스를 호출하는 바로 가기입니다.

예
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http({
method : "GET",
url : "welcome.htm"
}).then(function mySuccess(response) {
$scope.myWelcome = response.data;
}, function myError(response) {
$scope.myWelcome = response.statusText;
});
});

[전체소스]

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

<p>Today's welcome message is:</p>

<h1>{{myWelcome}}</h1>

</div>

<p>The $http service requests a page on the server, and the response is set as the value of the "myWelcome" variable.</p>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http({
method : "GET",
url : "welcome.htm"
}).then(function mySuccess(response) {
$scope.myWelcome = response.data;
}, function myError(response) {
$scope.myWelcome = response.statusText;
});
});
</script>

</body>
</html>

위의 예제는 객체를 인수로 사용하여 $ http 서비스를 실행합니다. 객체는 HTTP 메소드, URL, 성공시 수행 할 작업 및 실패시 수행 할 작업을 지정합니다.
|
댓글을 작성하시려면 로그인이 필요합니다.

퍼블리싱강좌

302건
+
분류 제목 글쓴이 날짜 조회
AngularJS
[AngularJS]
17-08-24 조회 1,538
AngularJS
[AngularJS]
17-08-24 조회 1,857
AngularJS 17-08-24 조회 1,761
AngularJS 17-08-23 조회 1,808
AngularJS 17-08-23 조회 2,472
AngularJS 17-08-23 조회 1,688
AngularJS 17-08-22 조회 1,724
AngularJS 17-08-22 조회 1,839
AngularJS 17-08-22 조회 2,248
AngularJS 17-08-20 조회 2,346
AngularJS 17-08-20 조회 1,923
AngularJS 17-08-20 조회 1,557
AngularJS 17-08-18 조회 1,893
AngularJS 17-08-18 조회 2,193
AngularJS 17-08-18 조회 1,467
AngularJS 17-08-17 조회 2,428
AngularJS 17-08-17 조회 1,521
AngularJS 17-08-17 조회 1,577
AngularJS 17-08-16 조회 1,769
AngularJS 17-08-16 조회 1,594
AngularJS 17-08-16 조회 2,386
AngularJS 17-08-15 조회 1,906
AngularJS 17-08-15 조회 2,217
AngularJS 17-08-15 조회 1,560
AngularJS 17-08-11 조회 2,546
AngularJS 17-08-11 조회 2,560
AngularJS 17-08-11 조회 2,356
AngularJS 17-08-10 조회 1,669
AngularJS 17-08-10 조회 2,145
AngularJS 17-08-09 조회 2,264