脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-AngularJSservice,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。
<!DOCTYPE htML> <html> <head> <meta charset="utf-8"> <script src="https://cdn.static.runoob.COM/libs/Angular.js/1.4.6/Angular.min.js"></script> </head> <body> <p ng-app="myApp" ng-controller="myCtrl"> <input type="number" ng-model="thing.mydata" required/> <!--输入类型为number--> <p>{{thing.mydata}} 的16进制是:</p> <h1>{{hex}}</h1> <h1>test, {{thing.mydata}} 的16进制是:{{hex1}}</h1> </p> <p>自定义服务,用于转换16进制数:</p> <script> VAR app = angular.module('myApp', []); app.service('hexafy', function() { this.myFunc = function (x) { //alert(x+" " + x.toString(16)); return x.toString(16); } }); app.controller('myCtrl', function($scope, hexafy, $interval) { $scope.thing = {mydata:100}; // 调用这个自定义服务都只执行一次 $scope.hex = hexafy.myFunc($scope.thing.mydata); $scope.hex1 = hexafy.myFunc($scope.thing.mydata); $interval(function () { // 使用定时器 每个500ms调用一次自定义服务即可 $scope.hex1 = hexafy.myFunc($scope.thing.mydata); }, 100); }); </script> </body> </html>
觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的javascript代码实例教程-AngularJSservice全部内容,希望文章能够帮你解决javascript代码实例教程-AngularJSservice所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。