(网页)angularjs中的interval定时执行功能(转)
转载博客园魔豆:
一个例子,用来显示当前实时时间,1秒钟刷新一次:
<!DOCTYPE html> <html ng-app="myApp"> <head> <meta charset="UTF-8"> <title>interval</title> <script type="text/javascript" src="js/angular/angular.min.js"></script> </head> <body ng-controller="ctrl"> <div>当前时间为:{{time}}</div> <script> var app = angular.module('myApp',[]); app.controller("ctrl",function($scope,$interval){ $interval(function(){ var time = new Date(); var t = time.getFullYear()+"年"+(time.getMonth()+1)+"月"+time.getDate() + "日 星期"+"日一二三四五六".charAt(time.getDay())+ " "+time.getHours() +":"+time.getMinutes()+":"+time.getSeconds(); $scope.time=t; },1000); }); </script> </body> </html>
原文地址:https://www.cnblogs.com/modou/p/5174282.html