angularJs自定义服务

来源:互联网 发布:鲜活的数据 pdf 下载 编辑:程序博客网 时间:2024/06/05 09:36


 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="libs/angular.min.js"></script> <script> var app= angular.module("gaoyn",[]); //使用的功能,需要 app.factory("gaoynsowTime",["$filter", function($filter){   var fdate=$filter("date");//获取过滤器---->日期过滤器   var now=new Date();   return fdate(now,'yyyy-MM-dd hh:mm:ss')   }]);   app.controller("democ",["$scope","gaoynsowTime",function($scope,gaoynsowTime){   $scope.now=gaoynsowTime;   console.log("当前时间",$scope.now); }]);   </script> </head> <body ng-app="gaoyn" ng-controller="democ"> {{now}} </body> </html> 
 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="libs/angular.min.js"></script> <script> var app= angular.module("gaoyn",[]); //使用的功能,需要 app.factory("gaoynsowTime",["$filter", function($filter){   var fdate=$filter("date");//获取过滤器---->日期过滤器   var now=new Date();   return fdate(now,'yyyy-MM-dd hh:mm:ss')   }]);   app.controller("democ",["$scope","gaoynsowTime",function($scope,gaoynsowTime){   $scope.now=gaoynsowTime;   console.log("当前时间",$scope.now); }]);   </script> </head> <body ng-app="gaoyn" ng-controller="democ"> {{now}} </body> </html>