Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument ... is not a function, got undefined

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(){  ... });}
like image 973
john mangual Avatar asked Mar 31 '13 21:03

john mangual


People also ask

Is not a function got undefined AngularJS?

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.

What is an Angular module?

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.


1 Answers

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.

like image 89
Deb Vorndran Avatar answered Oct 24 '22 19:10

Deb Vorndran