1

I'm having a lot of trouble finding out why my controller isn't defined in my MEAN stack. Every other controller is working just fine.

Error: Argument 'ReportsController' is not a function, got undefined
at assertArg (http://localhost:3000/lib/angular/angular.js:1039:11)
at assertArgFn (http://localhost:3000/lib/angular/angular.js:1049:3).....

app.js

window.app = angular.module('mean', ['ngCookies', 'ngResource', 'ui.bootstrap', 'ui.route', 'mean.system', 'mean.articles', 'mean.reports', 'angularFileUpload']);

angular.module('mean.system', []);
angular.module('mean.articles', []);
angular.module('mean.songs', []);
angular.module('mean.reports', []);

reports.js

angular.module('mean.reports').
controller('ReportsController',
    ['$scope', '$routeParams', '$location', 'Global', 'Reports',
        function ($scope, $routeParams, $location, Global, Reports) {
            $scope.global = Global;
            $scope.find = function() {
                    Reports.query(function(reports) {
                        $scope.reports = reports;
                    }
                );
            };
        }
    ]
);

routes.js

    //report routes
var reports = require('../app/controllers/reports');
app.get('/reports', reports.all);
app.post('/reports', auth.requiresLogin, reports.create);
app.get('/reports/:reportId', reports.show);
app.put('/reports/:reportId', auth.requiresLogin, auth.report.hasAuthorization, reports.update);
app.del('/reports/:reportId', auth.requiresLogin, auth.report.hasAuthorization, reports.destroy);


//Finish with setting up the reportId param
app.param('reportId', reports.report);

EDIT: Fixed - see comment

3
  • Apparently I didn't add the application service and controller to my 'foot.jade' file. THAT FIXED EVERYTHING Commented Nov 20, 2013 at 14:27
  • Without changes for controller code? Commented Nov 20, 2013 at 15:28
  • Yeah, I didn't need to change the controller code Commented Nov 23, 2013 at 19:24

1 Answer 1

1

You got that error because your controller definition in reports.js has errors: missing concluding ), }, ]...

Because of that it is not recognized as a function by angular function assertArg() which throws the error.

It should be something like (I unfold it to get errors easier):

angular.module('mean.reports').
    controller('ReportsController', 
        ['$scope', '$routeParams', '$location', 'Global', 'Reports', 
            function ($scope, $routeParams, $location, Global, Reports) {
                $scope.global = Global;
                $scope.find = function() {
                    Reports.query(function(reports) {
                            $scope.reports = reports;
                        }
                    ); // <-- missing
                }; // <-- missing
            } // <-- misssing
        ] // <-- missing
    );
    }; // is seems that should be deleted

Each opening (, [, or { should be properly closed by ), ], or }.

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

1 Comment

I unfolded it for you - it is the same as your code except I don't have the extra bracket at the end. I'm still getting the same error

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.