javascript - Breaking change from between AngularJS 1.2 and 1.4? -


the following code works in angular 1.2 breaks in 1.4 error error: [ng:areq] argument 'mycontroller' not function, got undefined. code comes book "ng-book", , live working example can found here: http://jsbin.com/uhivozo/1/edit?html,output.

what changed?

<body>     <div ng-controller="mycontroller">         {{ clock }}     </div>     <script type="text/javascript">         function mycontroller($scope) {             $scope.clock = new date();             var updateclock = function() {                 $scope.clock = new date();             };             setinterval(                 function() {                     $scope.$apply(updateclock);                 },                 1000             );             updateclock();         };     </script> </body> 

(replace https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0-rc.2/angular.js in jsbin link)

i didn't know version of angular allowed create controller without first creating module. in case, instantiating module , registering controller fix problem. jsbin

add app decalartion in html:

ng-app="app" 

modify script:

angular.module('app', []) // creates module  function mycontroller () { ... }  // register controller module angular.module('app').controller('mycontroller', mycontroller) 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -