Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNina Kozlova
11,602 PointsI get an error saying that "mainCtrl" is not a function and thus is undefined.
I've gone through the code with a fine-tooth comb, it's identical to what is on the screen. I mean, identical, every comma, every brace. So why is it not working?
Joel Kraft
Treehouse Guest TeacherDid you find an answer to your problem, Nina? Let us know, and be sure to include your code, as Steven mentioned, if you need more help. Thanks!
gececegecece
Courses Plus Student 4,065 PointsChange .controller to .controller('mainCtrl',['$scope',function($scope) { $scope.helloWorld = function() { console.log('This is the helloWorld controller function'); }; }]);
stevenqdinh
Courses Plus Student 7,836 PointsI had the same error: angular.js:12416 Error: [ng:areq] Argument 'mainCtrl' is not a function, got undefined
Here is the code:
angular.module("todoListApp", [])
.controller('mainCtrl', function($scope){
$scope.helloWorld = function() {
console.log("Hello there! this is the controller function.");
};
});
Joel Kraft
Treehouse Guest TeacherThat code works for me, stevenorton. Perhaps if you share the contents of your HTML file, I could troubleshoot further. Also, are you in workspaces? Or are you working on your local machine?
1 Answer
Aida Pandur
828 PointsIt is solved for me by changing the name of the controller same with the name of the js file. when I named the controller "app"
Steven Parker
231,275 PointsSteven Parker
231,275 PointsIf you post your code, or make a snapshot of your workspace and post the link, someone could look and perhaps identify and explain the issue.