<!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之自定义服务
最新推荐文章于 2022-09-28 10:29:52 发布