Implementation of the 60-second countdown function of AngularJS verification code and angularjs Verification Code

Source: Internet
Author: User

Implementation of the 60-second countdown function of AngularJS verification code and angularjs Verification Code

Recently I am working on the AngularJS project. This is a 60-second countdown. Unlike jq, angularjs does not use dom node operations, but data operations and write countdown. It is best to use $ timeout and $ interval, do not use settimeout and setinterval. $ Timeout and $ interval can directly update the bound data.

Html

<A href = "javascript:" rel = "external nofollow" ng-click = "sendphonecode (reg_phone) "ng-class =" paraclass "ng-bind =" paracont "> obtain the Verification Code </a>

Angularjs

Angular. module ('controllers', []). controller ('registerctrl ', function ($ scope, $ interval) {$ scope. paracont = "get verification code"; $ scope. paraclass = "but_null"; $ scope. paraevent = true; var second = 60, timePromise = undefined; timePromise = $ interval (function () {if (second <= 0) {$ interval. cancel (timePromise); timePromise = undefined; second = 60; $ scope. paracont = "resend verification code"; $ scope. paraclass = "but_null"; $ scope. paraevent = true;} else {$ scope. paracont = second + "resend after seconds"; $ scope. paraclass = "not but_null"; second -- ;}, 1000,100 );});

The above is the implementation of the 60-second countdown function of AngularJS Verification Code introduced by xiaobian. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.