<!DOCTYPE html>
<html lang="en" ng-app="myapp">
<head>
<meta charset="utf-8">
<script src="js/angular.js"></script>
</head>
<body ng-controller="myctrl">
<div>
255 的16進制是:{{hex}}<br>
255 的8進制是:{{octal}}
</div>
</body>
<script type="text/javascript">
var app = angular.module("myapp",[]);
<!-- 自定義服務hexafy,包含2個方法 myService和myService2-->
app.service('hahaha',function(){
this.myService = function(x){
return x.toString(16);
}
this.myService2 = function(x){
return x.toString(8);
}
});
<!-- 把服務傳入controller中-->
app.controller("myctrl",function($scope,hahaha){
$scope.hex = hahaha.myService(255);
$scope.octal = hahaha.myService2(255);
});
</script>
</html>
18-service之自定義服務
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.