Angularjs Getting Started 3-small example-timer

Source: Internet
Author: User

Implementation results:

Implementation code:

1 <!DOCTYPE HTML>2 <HTMLNg-app="">3 <Head><Scriptsrc= "./angular.min.js"></Script></Head>4 <Body>5 <H1>Timer Object</H1>6 <DivNg-controller= "ClockController">7 <h5>Time: {{clock}}</h5>8 </Div>9 <Scripttype= "Text/javascript">Ten functionClockController ($scope, $timeout) { One     varUpdateclock= function(){ A $scope. Clock= NewDate (); - $timeout (function(){ - Updateclock (); the         }, +); -     }; - Updateclock (); - }  + </Script>  - </Body> + </HTML>

Improved notation (best practice: Reference binding in a view through object properties rather than the object itself, is a best practice in angular):

1 functionClockController ($scope) {2$scope. Clock ={3NowNewDate ()4     };5     varUpdateclock =function(){6$scope. Clock.now =NewDate ();7     };8SetInterval (function(){9 $scope. $apply (updateclock);Ten},1000); One  A Updateclock (); -}

Angularjs Getting Started 3-small example-timer

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.