0

I've got a really simple Angular JS application, and I cannot figure out why I'm getting an error: Error: [ng:areq] Argument 'CoursesController' is not a function, got undefined

My fiddle (you'll need to open up your browser dev tools to see error in console): http://jsfiddle.net/Y4c2q/

My Angular JS code:

'use strict';
console.log('reg module entry');
var registrationModule = angular.module('registrationModule', []);

registrationModule.controller('CoursesController', function ($scope, bootStrappedData) {
    $scope.courses = bootStrappedData.courses;
    console.log('inside of controller');
});

registrationModule.factory('bootStrappedData', function() {
    console.log('bootstrapping our data');
    return {
courses: [{"number":"aaa","name":"magical creatures","instructor":"John"},
          {"number":"bbb","name":"ze dark arts","instructor":"Rob"},
          {"number":"ccc","name":"third book","instructor":"Bran"}]
     };
});

this is the HTML where I want to display my 3 rows of data:

<div ng-controller="CoursesController">
    <table class="table table-condensed table-hover">
        <tr>
            <th>Course</th>
            <th>Course Name</th>
            <th>Instructor</th>
        </tr>
        <tr ng-repeat="course in courses">
            <td>{{course.number}}</td>
            <td>{{course.name}}</td>
            <td>{{course.instructor}}</td>
        </tr>
    </table>
</div>
2
  • How is you application bootstrapped? Via ng-app or manually? Is registrationModule marked as dependency for main application module? Commented Jun 11, 2014 at 6:26
  • Did you checked my fiddle? If I understood your question correctly, according to this link (docs.angularjs.org/guide/bootstrap) I'm pretty sure I've used automatic bootstrapping. Commented Jun 11, 2014 at 6:39

1 Answer 1

4

This error is coming because your ng-app declaration is missing the module name. Use this

ng-app='registrationModule'

This would link the your modules and controller to the view.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.