自定义服务_显示当前时间

来源:互联网 发布:天互数据备案 编辑:程序博客网 时间:2024/06/08 06:28
<!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>

原创粉丝点击