Angular实时显示日期时间

DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AngularJS 内置服务title>
    <script src='./angular.min.js'>script>
head>
<body ng-app="App">
    <div ng-controller="DemoCtrl">
        <p>当前时间为: {{now|date:'yyyy-MM-dd hh:mm:ss'}}p>
        <button ng-click="stop()">停止button>
    div>
    <script>
        var App = angular.module('App', []);
        App.controller('DemoCtrl', ['$scope', '$timeout', '$interval', function ($scope, $timeout, $interval) {
             $scope.now = new Date();
            var timer = $interval(function () {
                $scope.now = new Date();
            }, 1000);

            $scope.stop = function () {
                $interval.cancel(timer);
            }
        }])

    script>
body>
html>

 

转载于:https://www.cnblogs.com/hughman/p/7066763.html

你可能感兴趣的:(Angular实时显示日期时间)