3

This is a very common problem apparently when declaring multiple controllers but every fix on this forum that I tried to follow or somewhere else, didn't seem to work (probably am missing something).

I have app.js file and 3 separate controller files and a services file.

I used one of the controllers and everything worked fine. Now I am trying to redirect to another view which handled by ProfileManagement controller, but it is showing the error:

Error: [ng:areq] Argument 'ProfileManagementController' is not a function, got undefined

This is what I have in the beginning of each controller file and also app.js...

app.js:

var app = angular.module('starter', ['ionic', 'starter.controllers', 'starter.services']);

app.run(function($ionicPlatform) {...

and in app.js, I am using this route before the error shows:

.state('tab.home', {
    url: '/home',
    views: {
      'tab-home': {
        templateUrl: 'templates/tab-home.html',
        controller: 'ProfileManagementController'
      }
    }
  })

My controllers are here...

UserAccessController:

app.controller('UserAccessController', ['$scope', '$http', '$state', '$q', '$rootScope', 'CreateUserService', 'UserObjectService', function($scope, $http, $state, $q, $rootScope, CreateUserService, UserObjectService){

and ProfileManagementController:

app.controller('ProfileManagementController', ['$scope', '$http', function($scope, $http){

}]);

Also with tabs project template of ionic framework, I got the file controller.js by default where I commented all controllers but left the first line:

angular.module('starter.controllers', []);

//.controller('ProfileController', function($scope) {})
//
//.controller('OrdersController', function($scope) {
//  
//})
//
//.controller('MoreOptionsController', function($scope, $stateParams) {
//  
//})
//
//.controller('ConnectionsController', function($scope) {
//  
//});

What am I doing wrong here that leads to the error message? (the view actually associated with the route tabs.home actually loads but the console shows the error.

Thanks,

5
  • Did you load the controller script to the html. I mean <script ...? Commented Nov 26, 2015 at 10:43
  • you mean the index.html or the sub-views? Commented Nov 26, 2015 at 10:43
  • Somewhere. index.html is better Commented Nov 26, 2015 at 10:44
  • yes I am updating the post now to show the index.html Commented Nov 26, 2015 at 10:44
  • oops forgot to add <script src="js/ProfileManagementController.js"></script> This actually fixed it. To close the question, if you want to post your recommendation and then I can select it as answer. Thanks Commented Nov 26, 2015 at 10:46

1 Answer 1

1

You probably forgot to add the script tag to define your controller within the html.

for example:

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

Comments

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.