Javascript angularJS中的超时函数
我正在尝试用angularJS实现一个简单的计时器。但超时功能不起作用,尽管大家都建议它Javascript angularJS中的超时函数,javascript,angularjs,timer,Javascript,Angularjs,Timer,我正在尝试用angularJS实现一个简单的计时器。但超时功能不起作用,尽管大家都建议它 <!doctype html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script> <script src="http://ajax.googleapis.com
<!doctype html>
<html lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-sanitize.min.js"></script>
</head>
<body>
<div ng-app="ss" ng-controller="mainCtrl">
{{timeInMs}}
</div>
<script>
var myApp = angular.module("ss", ['ngSanitize']);
myApp.controller('mainCtrl', function ($sce, $scope) {
$scope.timeInMs = 10;
var countUp = function() {
$scope.timeInMs+= 500;
$timeout(countUp, 500);
}
$timeout(countUp, 500);
});
</script>
</body>
</html>
{{timeInMs}}
var myApp=angular.module(“ss”,['ngSanitize']);
myApp.controller('mainCtrl',函数($sce,$scope){
$scope.timeInMs=10;
var countUp=函数(){
$scope.timeInMs+=500;
$timeout(倒计时,500);
}
$timeout(倒计时,500);
});
当我注释掉“$timeout(countUp,500);”行时,代码正常工作,但计时器不工作。我需要包含更多的javascript文件吗
提前谢谢 您必须将
$timeout
服务注入控制器
var myApp=angular.module(“ss”,[]);
myApp.controller('mainCtrl',函数($sce、$scope、$timeout){
$scope.timeInMs=10;
var countUp=函数(){
$scope.timeInMs+=500;
$timeout(倒计时,500);
}
$timeout(倒计时,500);
});代码>
{{timeInMs}}
您必须将$timeout
注入控制器。