AngularJS Services
AngularJS Services
서비스 란 무엇입니까?
AngularJS에서 서비스는 AngularJS 응용 프로그램에서만 사용할 수있는 함수 또는 객체입니다.
AngularJS에는 약 30 개의 내장 서비스가 있습니다. 그 중 하나가 $location 서비스입니다.
이 $location서비스에는 현재 웹 페이지의 위치에 대한 정보를 반환하는 메서드가 있습니다.
예
$location컨트롤러 에서 서비스를 사용하십시오 .
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $location) {
$scope.myUrl = $location.absUrl();
});
점을 유의 $location서비스가 인수로 컨트롤러에 전달됩니다. 컨트롤러에서 서비스를 사용하려면 서비스를 종속성으로 정의해야합니다.
[전체소스]
<!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>The url of this page is:</p>
<h3>{{myUrl}}</h3>
</div>
<p>This example uses the built-in $location service to get the absolute url of the page.</p>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $location) {
$scope.myUrl = $location.absUrl();
});
</script>
</body>
</html>
왜 서비스를 사용합니까?
서비스와 같은 많은 서비스의 $location경우 객체처럼 이미 DOM에있는 객체를 사용할 수있는 것처럼 보이지만 window.location 최소한 AngularJS 응용 프로그램에는 몇 가지 제한 사항이 있습니다.
AngularJS는 지속적으로 응용 프로그램을 관리하며 변경 및 이벤트를 올바르게 처리하기 위해 AngularJS는 객체 $location 대신 서비스 를 사용하는 것을 선호 window.location합니다.
$ http 서비스
이 $http서비스는 AngularJS 응용 프로그램에서 가장 일반적으로 사용되는 서비스 중 하나입니다. 이 서비스는 서버에 요청을 보내고 응용 프로그램이 응답을 처리하도록합니다.
예
이 $http서비스를 사용하여 서버에서 데이터를 요청 하십시오 .
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.get("welcome.htm").then(function (response) {
$scope.myWelcome = response.data;
});
});
이 예제는 $http서비스 의 매우 간단한 사용을 보여줍니다 . AngularJS Http 튜토리얼$http 에서 서비스에 대해 자세히 알아보십시오 .
서비스 란 무엇입니까?
AngularJS에서 서비스는 AngularJS 응용 프로그램에서만 사용할 수있는 함수 또는 객체입니다.
AngularJS에는 약 30 개의 내장 서비스가 있습니다. 그 중 하나가 $location 서비스입니다.
이 $location서비스에는 현재 웹 페이지의 위치에 대한 정보를 반환하는 메서드가 있습니다.
예
$location컨트롤러 에서 서비스를 사용하십시오 .
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $location) {
$scope.myUrl = $location.absUrl();
});
점을 유의 $location서비스가 인수로 컨트롤러에 전달됩니다. 컨트롤러에서 서비스를 사용하려면 서비스를 종속성으로 정의해야합니다.
[전체소스]
<!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>The url of this page is:</p>
<h3>{{myUrl}}</h3>
</div>
<p>This example uses the built-in $location service to get the absolute url of the page.</p>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $location) {
$scope.myUrl = $location.absUrl();
});
</script>
</body>
</html>
왜 서비스를 사용합니까?
서비스와 같은 많은 서비스의 $location경우 객체처럼 이미 DOM에있는 객체를 사용할 수있는 것처럼 보이지만 window.location 최소한 AngularJS 응용 프로그램에는 몇 가지 제한 사항이 있습니다.
AngularJS는 지속적으로 응용 프로그램을 관리하며 변경 및 이벤트를 올바르게 처리하기 위해 AngularJS는 객체 $location 대신 서비스 를 사용하는 것을 선호 window.location합니다.
$ http 서비스
이 $http서비스는 AngularJS 응용 프로그램에서 가장 일반적으로 사용되는 서비스 중 하나입니다. 이 서비스는 서버에 요청을 보내고 응용 프로그램이 응답을 처리하도록합니다.
예
이 $http서비스를 사용하여 서버에서 데이터를 요청 하십시오 .
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.get("welcome.htm").then(function (response) {
$scope.myWelcome = response.data;
});
});
이 예제는 $http서비스 의 매우 간단한 사용을 보여줍니다 . AngularJS Http 튜토리얼$http 에서 서비스에 대해 자세히 알아보십시오 .
게시판 목록
퍼블리싱강좌
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 178 | AngularJS | 8년 전 | 1417 | ||
| 177 | AngularJS | 8년 전 | 1191 | ||
| 176 | AngularJS | 8년 전 | 1269 | ||
| 175 | AngularJS | 8년 전 | 1362 | ||
| 174 | AngularJS | 8년 전 | 1132 | ||
| 173 | AngularJS | 8년 전 | 1872 | ||
| 172 | AngularJS | 8년 전 | 1425 | ||
| 171 | AngularJS | 8년 전 | 1121 | ||
| 170 | AngularJS | 8년 전 | 1387 | ||
| 169 | AngularJS | 8년 전 | 1185 | ||
| 168 | AngularJS | 8년 전 | 998 | ||
| 167 | AngularJS | 8년 전 | 1960 | ||
| 166 | AngularJS | 8년 전 | 1033 | ||
| 165 | AngularJS | 8년 전 | 1095 | ||
| 164 | AngularJS | 8년 전 | 1296 | ||
| 163 | AngularJS | 8년 전 | 1140 | ||
| 162 | AngularJS | 8년 전 | 1357 | ||
| 161 | AngularJS | 8년 전 | 1366 | ||
| 160 | AngularJS | 8년 전 | 1119 | ||
| 159 | AngularJS | 8년 전 | 1082 | ||
| 158 | AngularJS | 8년 전 | 1494 | ||
| 157 | AngularJS | 8년 전 | 1465 | ||
| 156 | AngularJS | 8년 전 | 1314 | ||
| 155 | AngularJS | 8년 전 | 1208 | ||
| 154 | AngularJS | 8년 전 | 1605 | ||
| 153 | AngularJS | 8년 전 | 1066 | ||
| 152 | AngularJS | 8년 전 | 1473 | ||
| 151 | AngularJS | 8년 전 | 1405 | ||
| 150 | AngularJS | 8년 전 | 1102 | ||
| 149 | AngularJS | 8년 전 | 1633 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기