夺命雷公狗—angularjs—15—内置封装好的计时器$interval和$timeout
这里其实和js源生的效果是一样的,但是源生的在angularjs里面不能直接正常执行代码如下所示:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="js/angular.min.js"></script> </head> <body ng-app="myapp"> <div ng-controller="app"> <p>{{num1}}</p> <p>{{num2}}</p> </div> </body> <script> var app = angular.module('myapp',[]); app.controller('app',function($scope,$interval,$timeout){ $scope.num1 = 0; $scope.num2 = 0; $interval(function(){ $scope.num1 = $scope.num1 + 1; },1000); $timeout(function(){ $scope.num2 = $scope.num2 + 1; },6000); }); </script> </html>
效果如下所示: