Argument 'MyCtrl' is not a function, got undefined
See original GitHub issueSo I keep getting the following: Error: [ng:areq] Argument 'AppsCtrl' is not a function, got undefined
when I try to define a few different modules. My setup looks like:
main.js
require.config({
paths: {
angular: 'lib/angular/angular',
jquery: 'lib/jquery/jquery-2.1.0',
angularCookies: "lib/angular/angular-cookies",
angularRoute: "lib/angular/angular-route",
angularAnimate: "lib/angular/angular-animate",
angularTouch: "lib/angular/angular-touch",
angularSanitize: "lib/angular/angular-sanitize",
angularAMD: 'lib/angularAMD/angularAMD',
ngload: 'lib/angularAMD/ngload'
},
map: {
'*': {
'less': 'lib/require/require-less/less',
}
},
shim: {
jquery: {
exports: '$'
},
angular: {
exports: 'angular',
deps: ['jquery']
},
angularAMD: ['angular'],
ngload: ['angularAMD']
}
});
require(['angular', 'angularAMD', 'app/app'], function (angular, angularAMD, app) {
angularAMD.bootstrap(app);
});
app.js
define(['angular',
'angularCookies',
'angularRoute',
'angularAnimate',
'angularTouch',
'angularSanitize',
'app/admin/admin' // module trying to be included!
], function (angular) {
var app = angular.module('phx', ['ngCookies', 'ngRoute', 'ngAnimate', 'ngSanitize', 'admin']);
app.config(function ($routeProvider, $locationProvider) {
$routeProvider.otherwise({ redirectTo: 'apps' });
$locationProvider.html5Mode(true);
});
app.run(function ($rootScope, $location, $route, Auth) {
var deregister = $rootScope.$on("$routeChangeStart", function () {
Auth.authorize().then(function (xhr) {
if (xhr) {
$rootScope.authed = true;
$rootScope.profile = xhr.data;
deregister();
}
},function(){
$location.path('login');
});
});
$rootScope.$on('$routeChangeSuccess', function() {
if ($route.current && $route.current.$$route && $route.current.$$route.controller){
$rootScope.controller = $route.current.$$route.controller;
$rootScope.page_title = $route.current.$$route.title;
}
});
});
return app;
});
admin.js
define(['angular', 'angularAMD'], function (angular, angularAMD) {
var module = angular.module('admin', []);
module.config(function ($routeProvider) {
// admin/apps/apps.js
$routeProvider.when('/apps',
angularAMD.route({
templateUrl: 'app/admin/apps/apps.tpl.html',
controller: 'AppsCtrl',
title: 'Applications',
controllerUrl: 'app/admin/apps/apps',
resolve: {
apps: function (AppsModel) {
return AppsModel.findAll();
}
}
}));
});
return module;
});
It happens when the route hits the app. I added console logs and everything is getting hit its just timing related.
Anyone got any ideas?
Issue Analytics
- State:
- Created 10 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Error: Argument is not a function, got undefined - Stack Overflow
If you don't declare subModule1 in mainApp, you will got a "[ng:areq] Argument "MyController" is not a function, got undefined.
Read more >Argument 'ProductListCtrl' is not a function, got undefined #6
I've tried creating the app twice now and keep getting stuck tying to call the WebAPI. It isn't a CORS error. Instead I'm...
Read more >Argument 'mainCtrl' is not a function, got undefined - Treehouse
In my console I get an error that says "Error: [ng:areq] Argument 'mainCtrl' is not a function, got undefined." The error references the...
Read more >Error: [ng:areq] Argument 'MyCtrl' is not a function, got undefined
I am getting this error message every time. My code works in jsfiddle however when I copy and past the exact same code...
Read more >Getting Error "[ng:areq] Argument 'myCtrl' is not a function, got ...
User1914091530 posted. Hi,. I am getting Error "[ng:areq] Argument 'myCtrl' is not a function, got undefined". My index.html code is
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looking at your code, the problem seems to be related to the call to
angularAMD.bootstrap(app)
in yourmain.js
instead of yourapp.js
. Afterbootstrap
is called,angular.module
no longer works and you should be callingapp.register...
instead. Try to move the bootstraping to the end app.js and kick off your app.js usingdeps: ['app']
in yourrequire.config
.Also, as you defined
angular
as dependency toangularAMD
in yourrequire.config
, there is really no reason to includeangular
inapp.js
oradmin.js
.If this doesn’t solve your problem, setup a JSFiddle or Plunker and I will try to help further.
you may forget include js file