0

MainController.js

(function(){

    var eateryControllers=angular.module('eateryControllers',[]);

    eateryControllers.controller('MainController',function(){

        var mainCtrl=this;
    });

})();

ReservationController.js

(function(){

    var eateryControllers=angular.module('eateryControllers');

    eateryControllers.controller('ReservationController',reservationController);
    function reservationController(){
        var resvnCtrl=this;
        resvnCtrl.user={};
    }

})();

I am creating module in first file and reusing the same module in second file.

Error

http://errors.angularjs.org/1.4.7/ng/areq?p0=ReservationController&p1=not%20aNaNunction%2C%20got%20undefined
    at Error (native)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:6:416
    at qb (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:22:131)
    at Sa (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:22:218)
    at b.$get (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:80:81)
    at g.link (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-route.min.js:7:268)
    at aa 
3
  • 1
    are these two files included in your HTML, and in the correct order? Commented Oct 15, 2015 at 16:45
  • 1
    I think your ReservationController.js file is getting call before MainController.js file so the module is not getting initiated Commented Oct 15, 2015 at 16:46
  • 1
    you probably should put your 'reservationController' function above the definition of your angular controller Commented Oct 15, 2015 at 16:46

2 Answers 2

2

you should put your 'reservationController' function above the definition of your angular controller once youre trying to use a function before defining it

(function(){

    var eateryControllers=angular.module('eateryControllers');
    function reservationController(){
        var resvnCtrl=this;
        resvnCtrl.user={};
    }
    eateryControllers.controller('ReservationController',reservationController);

})();
Sign up to request clarification or add additional context in comments.

Comments

1

You have defined your controller as 'ReservationController' and used in your code as 'ResevationController'. Error is due to typo

2 Comments

He's not doing that. Read the error description pasted on code. He just missed the name on title that probably he wroted manualy
@Guilherme Ferreira you are right. I should have seen the stack trace before answering that. Thanks for pointing

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.