前端之家收集整理的这篇文章主要介绍了
angularjs之定时器,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<!DOCTYPE html>
<html lang="en">
<head>
<Meta charset="UTF-8">
<title>angularjs指令</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
<script src="jquery-2.1.3.min.js"></script>
<script src="bootstrap.min.js"></script>
<script src="angular.min.js"></script>
</head>
<body ng-app="kongwc" ng-controller="myCtrl">
<h1>{{name}}</h1>
<h1>{{num}}</h1>
</body>
<script>
var app = angular.module("kongwc",[]);
app.controller("myCtrl",function ($scope,$timeout,$interval) {
$scope.name = "小白牛";
$scope.num = 1;
var turnName = $timeout(function () {
$scope.name = "裂魂人";
},2000);
//$timeout.cancel(turnName); //取消定时器
var turnName1 = $interval(function () {
$scope.num += 1;
if($scope.num == 10){
$interval.cancel(turnName1); //取消定时器
}
},1000);
});
</script>
</html>
原文链接:https://www.f2er.com/angularjs/146969.html