"Angular authoritative course" reading notes 1

Source: Internet
Author: User

began to learn Angularjs, is reading the "angular authoritative tutorial."

The most depressing thing about learning Angularjs is the ANGULARJS version. In the book, there are many examples on the internet, often in the newer version of the run is not up, so open a paste, while reading the change, the book to change the example to 1.4.1 available.

"Angular authoritative course" chapter II, page 7th:

The original code can be run on 1.2X:

1 <!DOCTYPE HTML>2 <HTMLNg-app> 3 <Head> 4     <Scriptsrc= "Http://cdn.bootcss.com/angular.js/1.2.0rc3/angular.min.js"></Script>5 </Head>6 <Body>   7     <DivNg-controller= "Mycontroller">    8     <H1>Hello {{Clock}}!</H1> 9 </Div>   Ten <Scripttype= "Text/javascript">  One     functionMycontroller ($scope, $timeout) { A         varUpdateclock= function() {  - $scope. Clock= NewDate (); - $timeout (function() {  the Updateclock ();}, +); -         };  - Updateclock (); -     };  + </Script>   - </Body>  + </HTML> 

Error after 1.3X:Argument ' Mycontroller ' is not a function, got undefined

Reason: With angular 1.3+ you can no longer use global controllers declaration on the global scope (without explicit registratio n). You would need to register the controller using module.controller syntax.

Starting with the angular 1.3X, you cannot use the Global Controller declaration (not explicitly registered) in global scope and use the Module.controller syntax to register the controller.

Modified version:

1 <!DOCTYPE HTML>2 <HTMLNg-app= "MYAPP">3 <Head>4     <title>Chap2p7</title>5 </Head>6 <Body>7 <DivNg-controller= "Mycontroller">8     <H1>Hello<spanNg-bind= "Clock"></span></H1>9 </Div>Ten <Scriptsrc= "Http://cdn.bootcss.com/angular.js/1.4.1/angular.min.js"></Script> One <Scripttype= "Text/javascript"> A     varmyApp=Angular.module ('MyApp', []); - Myapp.controller ("Mycontroller", function($scope, $timeout) { -            varUpdateclock= function() {                 the $scope. Clock= (NewDate). toLocaleString () - $timeout (function() {  - Updateclock ();}, +); -         };  + Updateclock (); - }); + </Script> A </Body> at </HTML>

"Angular authoritative course" reading notes 1

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.