Timeout function in angularJS

前端 未结 1 1451
自闭症患者
自闭症患者 2020-12-20 09:39

I am trying to implement a simple timer in angularJS. But timeout function is not working though it is suggested by everyone.




        
1条回答
  •  时光取名叫无心
    2020-12-20 09:51

    You have to inject the $timeout service to the controller

    var myApp = angular.module("ss", []);
    myApp.controller('mainCtrl', function ($sce, $scope, $timeout) {
    
        $scope.timeInMs = 10;
    
        var countUp = function () {
            $scope.timeInMs += 500;
            $timeout(countUp, 500);
        }
        $timeout(countUp, 500);
    });
    
    
    {{timeInMs}}

    0 讨论(0)
提交回复
热议问题