1

I have a main.html with multiple subpages:users.html,usergroups.html,... which all of them have their own app files and controllers separately: mainapp.js,usersapp.js,usergroupsapp.js,...

And I use ui-router to route to particular sub page as needed:

var myApp = angular.module("myApp",['ui.router']);
    myApp.config(function($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state('users', {
      url: "/users",
      templateUrl: "pages/users.html",
      controller : 'UsersCtrl'
    })
    .state('usergroups', {
      url: "/usergroups",
      templateUrl: "pages/usergroups.html",
      controller : 'UsergroupsCtrl'
    })

...

Everything works fine until I need to use one of the module multiselect.jsin my usergroups.html. When I added it directly to UsergroupsCtrl in usergroupsapp.js:

var app= angular.module('myApp',['am.multiselect']);
...

But immediately I have an error:

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

Which MainCtrl is from main app.js. How can I resolve this issue?

1
  • There can be version conflict-ion for multiselect.js and anular.js. Commented Nov 24, 2015 at 9:29

1 Answer 1

2

Here is correct way to add am.multiselect module dependency to your main myApp module:

var myApp = angular.module("myApp", ['ui.router', 'am.multiselect']);

In usergroupsapp.js you should just have module getter, not setter (don't recreate module once again). Note, that there are no [...] when you retrieve existing module:

var app = angular.module('myApp');
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.