gadin gadin - 1 month ago 22
AngularJS Question

Ionic cannot find my controller

I am trying to integrate a side menu into my already existing app. So that means that I have to change how my controllers are setup. I added a menu controller, but the app keeps throwing me this error:

Argument 'MenuCtrl' is not a function, got undefined


Here is my old app.js file:



.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'templates/home.html',
controller: 'HomeCtrl'
})

.state('login', {
url: '/login',
templateUrl: 'templates/login.html'
//controller: 'LoginCtrl'
})

.state('messaging', {
url: '/messaging',
templateUrl: 'templates/messaging.html'
//controller: 'MessageCtrl'
})

.state('equipment', {
url: '/equipment',
templateUrl: 'templates/equipment.html'
})

$urlRouterProvider.otherwise('/home');
})





Then I made these changes to setup my side menu:



.config(function($stateProvider, $urlRouterProvider) {
$stateProvider

.state('app', {
url: '/app',
templateUrl: 'templates/menu.html',
controller: 'MenuCtrl'
})

.state('app.home', {
url: '/home',
templateUrl: 'templates/home.html',
controller: 'HomeCtrl'
})

.state('app.login', {
url: '/login',
templateUrl: 'templates/login.html'
//controller: 'LoginCtrl'
})

.state('app.messaging', {
url: '/messaging',
templateUrl: 'templates/messaging.html'
//controller: 'MessageCtrl'
})

.state('app.equipment', {
url: '/equipment',
templateUrl: 'templates/equipment.html'
})



$urlRouterProvider.otherwise('/app/home');
})





That is where i get the above error. I have created a MenuCtrl.js and set it up like this:



angular.module('App')

.controller('MenuCtrl', function () {

})





I do not understand why it cannot find the controller. Ive done it just like all my other controllers. It is driving me insane!

Thanks in advance stack.

Answer

You may have forgotten to include MenuCtrl.js in your index.html. Right now Angular doesn't know how to find the controller, because it is not being loaded.

Comments