marcoslin / angularAMD

Facilitate use of RequireJS in AngularJS
http://marcoslin.github.io/angularAMD
MIT License
734 stars 171 forks source link

Type error: #82

Closed hawkwind2 closed 10 years ago

hawkwind2 commented 10 years ago

I'm getting this error haven't found out why type_err :

define(['app'], function (app) {
    app.controller('HomeController', function ($scope) {
**//Uncaught TypeError: Cannot read property 'controller' of undefined  **
        $scope.message = "message from home ctrl";
        console.log("Home ctrl");
    });
});

Well, I've replace the return under app.js with this: return app;
instead of: return angularAMD.bootstrap(app); But now the home controller is not loading at all...

marcoslin commented 10 years ago

If you are using version 0.2.X and above, you must return angularAMD.bootstrap(app) as it will create a version of app that allow for lazy loading.

hawkwind2 commented 10 years ago

Thank you @marcoslin, I'm using V0.2.0...but now I'm getting an error: "Unable to get property 'controller' of undefined or null reference", same controller code as above; My 'app' is undefined.. What I'm trying to do is route to .NET MVC controller, thus my templateUrl is pointing, hopefully, to my MVC controller e.g. templateUrl: '/Partials/Home' returning a PartialView. This is working for me on a different project using AngularJS non-lazy though. Please, any idea why am I getting this error?

marcoslin commented 10 years ago

If you app is undefined, it means that there is something wrong in you app.js or main.js.

Try to start with something simple, use template I created:

http://bl.ocks.org/marcoslin/df4b741e92b2829eeae8

Make sure that you relative path is set correct.

hawkwind2 commented 10 years ago

Cool! Works with MVC 5 now. Thanks!!! Created a separate project as you suggested and had changed the path for the main.js to "/Scripts/main.js" then changed the baseUrl: "Scripts" and placed the "app.js" in the same folder as "main.js" and the controllers as well. When I saw it's working :) I later had changed file location to suit my preferences.