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>
게시판 목록
퍼블리싱강좌
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 268 | 부트스트랩 | 8년 전 | 3141 | ||
| 267 | 부트스트랩 | 8년 전 | 2925 | ||
| 266 | 부트스트랩 | 8년 전 | 2914 | ||
| 265 | 부트스트랩 | 8년 전 | 3406 | ||
| 264 | 부트스트랩 | 8년 전 | 3148 | ||
| 263 | 부트스트랩 | 8년 전 | 3223 | ||
| 262 | 부트스트랩 | 8년 전 | 2722 | ||
| 261 | 부트스트랩 | 8년 전 | 4844 | ||
| 260 | 부트스트랩 | 8년 전 | 3217 | ||
| 259 | 부트스트랩 | 8년 전 | 2762 | ||
| 258 | 부트스트랩 | 8년 전 | 2788 | ||
| 257 | 부트스트랩 | 8년 전 | 2814 | ||
| 256 | 부트스트랩 | 8년 전 | 3304 | ||
| 255 | 부트스트랩 | 8년 전 | 3492 | ||
| 254 | 부트스트랩 | 8년 전 | 3227 | ||
| 253 | 부트스트랩 | 8년 전 | 4104 | ||
| 252 | 부트스트랩 | 8년 전 | 2888 | ||
| 251 | 부트스트랩 | 8년 전 | 2612 | ||
| 250 | 부트스트랩 | 8년 전 | 2717 | ||
| 249 | 부트스트랩 | 8년 전 | 2427 | ||
| 248 | 부트스트랩 | 8년 전 | 1973 | ||
| 247 | 부트스트랩 | 8년 전 | 1729 | ||
| 246 | 부트스트랩 | 8년 전 | 2001 | ||
| 245 | 부트스트랩 | 8년 전 | 1522 | ||
| 244 | 부트스트랩 | 8년 전 | 2138 | ||
| 243 | 부트스트랩 | 8년 전 | 1890 | ||
| 242 | 부트스트랩 | 8년 전 | 1783 | ||
| 241 | 부트스트랩 | 8년 전 | 1171 | ||
| 240 | 부트스트랩 | 8년 전 | 1621 | ||
| 239 | 부트스트랩 | 8년 전 | 1652 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기