0

Error: [ng:areq] http://errors.angularjs.org/1.3.15/ng/areq?p0=homeController&p1=not%20aNaNunction%2C%20got%20undefined

I am getting the above error

Controller.js

angular.module('app').controller('homeController', function($scope) {});

app.js

 var app = angular.module('app', ['base', 'ngRoute', 'routeResolverServices']);
angular.bootstrap(document, ['app']);
return app;
2
  • 1
    share your html file Commented May 27, 2015 at 5:33
  • 1
    wrapping angular.bootstrap(document, ['app']); in angular.element ready will solve your issue Commented May 27, 2015 at 5:47

1 Answer 1

2

This doesn't work because of the order of your scripts (and wouldn't work in any order the way you defined it). When Controller.js loads first, there is is still no module named "app". When app.js loads first, it immediately bootstraps the app without the controller.

It's best to define one module per file, for example:

feature1.js

angular.module("feature1", []).controller("homeController", function(){});

app.js

var app = angular.module('app', 
             ['base', 'feature1', 'ngRoute', 'routeResolverServices']);
app.bootstrap(document, ['app']);

and load app.js last:

<script src="feature1.js"></script>
<scirpt src="app.js"></script>
Sign up to request clarification or add additional context in comments.

5 Comments

Hi, thank you so much the reply. I did as you said and it works for me well.. But I have to load all the controllers dynamically on the fly.. I have used requirejs also.
@vinothini, not sure what you mean by "on the fly" or "dynamically"... but in any case, this should be a different (new) question
OP would have gotten a different error (nomod) if they had the files the wrong way around. Still, good advice
@Phil, yeah... and I said that it wouldn't have worked in either order

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.