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년 전 | 1925 | ||
| 87 | jQuery Mobile | 8년 전 | 1910 | ||
| 86 | jQuery Mobile | 8년 전 | 1515 | ||
| 85 | jQuery Mobile | 8년 전 | 1825 | ||
| 84 | jQuery Mobile | 8년 전 | 1863 | ||
| 83 | jQuery Mobile | 8년 전 | 1876 | ||
| 82 | jQuery Mobile | 8년 전 | 1647 | ||
| 81 | jQuery Mobile | 8년 전 | 1368 | ||
| 80 | jQuery Mobile | 8년 전 | 1805 | ||
| 79 | jQuery Mobile | 8년 전 | 1355 | ||
| 78 | jQuery Mobile | 8년 전 | 1750 | ||
| 77 | jQuery Mobile | 8년 전 | 1777 | ||
| 76 | jQuery Mobile | 8년 전 | 1784 | ||
| 75 | jQuery Mobile | 8년 전 | 1398 | ||
| 74 | jQuery Mobile | 8년 전 | 1536 | ||
| 73 | jQuery Mobile | 8년 전 | 1245 | ||
| 72 | jQuery Mobile | 8년 전 | 1626 | ||
| 71 | jQuery Mobile | 8년 전 | 1617 | ||
| 70 | jQuery Mobile | 8년 전 | 1500 | ||
| 69 | jQuery Mobile | 8년 전 | 1508 | ||
| 68 | jQuery Mobile | 8년 전 | 2041 | ||
| 67 | jQuery Mobile | 8년 전 | 1314 | ||
| 66 | jQuery Mobile | 8년 전 | 1690 | ||
| 65 | jQuery Mobile | 8년 전 | 1183 | ||
| 64 | jQuery Mobile | 8년 전 | 1465 | ||
| 63 | jQuery Mobile | 8년 전 | 1650 | ||
| 62 | jQuery Mobile | 8년 전 | 1630 | ||
| 61 | jQuery Mobile | 8년 전 | 1873 | ||
| 60 | jQuery Mobile | 8년 전 | 1402 | ||
| 59 | jQuery Mobile | 8년 전 | 1961 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기