I'm playing with AngularJS, but I'm getting an error message: Argument 'Controller' is not a function, got undefined
Here's the JSFiddle, and HTML code:
<h2>Hata's Tree-Like Set</h2>
<div ng-app ng-init="N=3;" ng-controller="Controller">
<input type="range" min="1" max="10" step="1" ng-model="N">
<div class="tree"></div>
</div
Then I define the Controller
function in JavaScript, which is not registering for some reason.
function Controller($scope){
$scope.$watch("N", function(){ ... });}
You need to use the . controller() method of one of your AngularJS modules to declare a function as a controller. You first have to create a main module and load it with ng-app attribute, then create a controller in that module using controller method.
In Angular, a module is a mechanism to group components, directives, pipes and services that are related, in such a way that can be combined with other modules to create an application. An Angular application can be thought of as a puzzle where each piece (or each module) is needed to be able to see the full picture.
I had exactly the same error: argument 'HelloCtrl' is not a function
, got undefined.
Turns out I had a syntax error in my hello.js
file... a missing comma in an array definition, inside HelloCtrl()
.
I added the comma, and then everything started working!
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With