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 에서 서비스에 대해 자세히 알아보십시오 .
게시판 목록
퍼블리싱강좌
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 118 | jQuery Mobile | 8년 전 | 1347 | ||
| 117 | jQuery Mobile | 8년 전 | 1594 | ||
| 116 | jQuery Mobile | 8년 전 | 1825 | ||
| 115 | jQuery Mobile | 8년 전 | 1780 | ||
| 114 | jQuery Mobile | 8년 전 | 1970 | ||
| 113 | jQuery Mobile | 8년 전 | 1879 | ||
| 112 | jQuery Mobile | 8년 전 | 2486 | ||
| 111 | jQuery Mobile | 8년 전 | 1792 | ||
| 110 | jQuery Mobile | 8년 전 | 1584 | ||
| 109 | jQuery Mobile | 8년 전 | 1744 | ||
| 108 | jQuery Mobile | 8년 전 | 1969 | ||
| 107 | jQuery Mobile | 8년 전 | 1772 | ||
| 106 | jQuery Mobile | 8년 전 | 1450 | ||
| 105 | jQuery Mobile | 8년 전 | 1747 | ||
| 104 | jQuery Mobile | 8년 전 | 2424 | ||
| 103 | jQuery Mobile | 8년 전 | 1562 | ||
| 102 | jQuery Mobile | 8년 전 | 1504 | ||
| 101 | jQuery Mobile | 8년 전 | 1696 | ||
| 100 | jQuery Mobile | 8년 전 | 1922 | ||
| 99 | jQuery Mobile | 8년 전 | 1375 | ||
| 98 | jQuery Mobile | 8년 전 | 1399 | ||
| 97 | jQuery Mobile | 8년 전 | 1658 | ||
| 96 | jQuery Mobile | 8년 전 | 1310 | ||
| 95 | jQuery Mobile | 8년 전 | 1127 | ||
| 94 | jQuery Mobile | 8년 전 | 1528 | ||
| 93 | jQuery Mobile | 8년 전 | 1148 | ||
| 92 | jQuery Mobile | 8년 전 | 1570 | ||
| 91 | jQuery Mobile | 8년 전 | 1516 | ||
| 90 | jQuery Mobile | 8년 전 | 1681 | ||
| 89 | jQuery Mobile | 8년 전 | 1668 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기