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