Home > Web Front-end > JS Tutorial > How to implement timer function using Angular

How to implement timer function using Angular

亚连
Release: 2018-06-14 16:43:53
Original
2225 people have browsed it

This article mainly introduces the simple timer function implemented by Angular, and analyzes the simple implementation and usage skills of the AngularJS timer function in the form of examples. Friends in need can refer to it

The examples in this article describe Angular Implemented simple timer function. Share it with everyone for your reference, the details are as follows:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>www.jb51.net Angular定时器</title>
  <script src="angular.min.js"></script>
  <script>
    var myapp=angular.module("myapp",[]);
    myapp.controller("myCtrl",function ($scope,$interval,$timeout) {
      $scope.num=0;
      $scope.fun=function () {
//        $interval(function () {
//          $scope.num++
//        },1000)
//        setInterval(function () {
//          $scope.$apply(function () {
//            $scope.num++;
//            console.log($scope.num)
//          })
//        },1000);
//                $interval(function () {
//
//            $scope.num++;
//            console.log($scope.num);
//
//        },1000,5,false);
        $timeout(function () {
          $scope.num++;
        },1000);
      }
    })
  </script>
</head>
<body ng-app="myapp" ng-controller="myCtrl">
<p>{{num}}</p>
<button ng-click="fun()">按钮</button>
</body>
</html>
Copy after login

The above is what I compiled for everyone, I hope it will be helpful to everyone in the future.

Related articles:

Detailed interpretation of Angular’s ​​error 404 issues

How to use the switch selector in WeChat mini programs

How to calculate polygon centroid in JavaScript

About the use of custom form controls in Angular19

The above is the detailed content of How to implement timer function using Angular. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template