AngularJS Services 나만의 서비스 만들기
나만의 서비스 만들기
자체 서비스를 만들려면 서비스를 모듈에 연결하십시오.
다음과 같은 서비스를 만듭니다 hexafy.
app.service('hexafy', function() {
this.myFunc = function (x) {
return x.toString(16);
}
});
사용자 정의 된 서비스를 사용하려면 컨트롤러 정의시 종속성으로 추가하십시오.
예
이름 hexafy을 16 진수로 변환하려면 명명 된 사용자 지정 서비스를 사용하십시오 .
app.controller('myCtrl', function($scope, hexafy) {
$scope.hex = hexafy.myFunc(255);
});
[전체소스]
<!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 hexadecimal value of 255 is:</p>
<h1>{{hex}}</h1>
</div>
<p>A custom service with a method that converts a given number into a hexadecimal number.</p>
<script>
var app = angular.module('myApp', []);
app.service('hexafy', function() {
this.myFunc = function (x) {
return x.toString(16);
}
});
app.controller('myCtrl', function($scope, hexafy) {
$scope.hex = hexafy.myFunc(255);
});
</script>
</body>
</html>
자체 서비스를 만들려면 서비스를 모듈에 연결하십시오.
다음과 같은 서비스를 만듭니다 hexafy.
app.service('hexafy', function() {
this.myFunc = function (x) {
return x.toString(16);
}
});
사용자 정의 된 서비스를 사용하려면 컨트롤러 정의시 종속성으로 추가하십시오.
예
이름 hexafy을 16 진수로 변환하려면 명명 된 사용자 지정 서비스를 사용하십시오 .
app.controller('myCtrl', function($scope, hexafy) {
$scope.hex = hexafy.myFunc(255);
});
[전체소스]
<!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 hexadecimal value of 255 is:</p>
<h1>{{hex}}</h1>
</div>
<p>A custom service with a method that converts a given number into a hexadecimal number.</p>
<script>
var app = angular.module('myApp', []);
app.service('hexafy', function() {
this.myFunc = function (x) {
return x.toString(16);
}
});
app.controller('myCtrl', function($scope, hexafy) {
$scope.hex = hexafy.myFunc(255);
});
</script>
</body>
</html>
게시판 목록
퍼블리싱강좌
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 88 | jQuery Mobile | 8년 전 | 1937 | ||
| 87 | jQuery Mobile | 8년 전 | 1917 | ||
| 86 | jQuery Mobile | 8년 전 | 1528 | ||
| 85 | jQuery Mobile | 8년 전 | 1836 | ||
| 84 | jQuery Mobile | 8년 전 | 1873 | ||
| 83 | jQuery Mobile | 8년 전 | 1886 | ||
| 82 | jQuery Mobile | 8년 전 | 1657 | ||
| 81 | jQuery Mobile | 8년 전 | 1373 | ||
| 80 | jQuery Mobile | 8년 전 | 1810 | ||
| 79 | jQuery Mobile | 8년 전 | 1357 | ||
| 78 | jQuery Mobile | 8년 전 | 1756 | ||
| 77 | jQuery Mobile | 8년 전 | 1782 | ||
| 76 | jQuery Mobile | 8년 전 | 1791 | ||
| 75 | jQuery Mobile | 8년 전 | 1405 | ||
| 74 | jQuery Mobile | 8년 전 | 1543 | ||
| 73 | jQuery Mobile | 8년 전 | 1249 | ||
| 72 | jQuery Mobile | 8년 전 | 1630 | ||
| 71 | jQuery Mobile | 8년 전 | 1622 | ||
| 70 | jQuery Mobile | 8년 전 | 1506 | ||
| 69 | jQuery Mobile | 8년 전 | 1514 | ||
| 68 | jQuery Mobile | 8년 전 | 2050 | ||
| 67 | jQuery Mobile | 8년 전 | 1317 | ||
| 66 | jQuery Mobile | 8년 전 | 1695 | ||
| 65 | jQuery Mobile | 8년 전 | 1187 | ||
| 64 | jQuery Mobile | 8년 전 | 1468 | ||
| 63 | jQuery Mobile | 8년 전 | 1659 | ||
| 62 | jQuery Mobile | 8년 전 | 1640 | ||
| 61 | jQuery Mobile | 8년 전 | 1877 | ||
| 60 | jQuery Mobile | 8년 전 | 1412 | ||
| 59 | jQuery Mobile | 8년 전 | 1967 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기