AngularJS 定时器(获取当前日期)

来源:互联网 发布:java设置全局编码格式 编辑:程序博客网 时间:2024/06/04 19:36
<!DOCTYPE html><html lang="en" ng-app="App"><head><meta charset="UTF-8"><title>AngularJS 服务</title></head><body><div ng-controller="DemoController"><ul><li>{{msg}}</li><li>{{now|date: 'yyyy-MM-dd hh:mm:ss'}}</li><li><button ng-click="stop()">停</button></li></ul></div><script src="./libs/angular.min.js"></script><script>var App = angular.module('App', []);App.controller('DemoController', ['$scope', '$timeout', '$interval',function ($scope, $timeout, $interval) {$timeout(function () {// console.log('执行了');$scope.msg = '执行了';}, 3000);// var i = 0;var timer = $interval(function () {// console.log(++i);$scope.now = new Date;}, 1000);$scope.stop = function () {$interval.cancel(timer);}}]);</script></body></html>

0 0
原创粉丝点击