0

I want to add module dependencies based on controllers. I don't always need all the dependencies which is killing for the performance of the app. Is there a way to add dependencies into a controller?

var angularApp = angular.module('myModule', [
    'angular-cache', 'mwl.calendar', 'ui.bootstrap', 'ngRoute'
]);
3
  • Make different modules for different work and make them dependent to each other not controllers. Commented Mar 14, 2016 at 10:52
  • First of all: why is the question not useful? And isn't there another method instead of creating new modules with all the same config except the dependencies? Commented Mar 14, 2016 at 10:55
  • Its Angular structure thats the way it works you can have dependent modules controllers are not dependent on other controllers they depend on modules. Commented Mar 14, 2016 at 11:00

1 Answer 1

2

Dependencies need to be handled on the module level. So, every module includes what it needs.

What you can do is define separate module for your app and add the controller to that module. Example:

Main module:

var angularApp = angular.module('myModule', [
    'angular-cache', 'ui.bootstrap', 'ngRoute', 'ScheduleModule'
]);

Sub-module:

angular.module('ScheduleModule', [
    'mwl.calendar'
]);

Controller part of the submodule:

angular.module('ScheduleModule').controller('MyContoller', function(){
.............
});

This is really the way to go. As your app grows you will start to see the benefits of it, even if you maybe don't see them now. There is a lot of good content on the web about the angular app modularity and I don't want to copy/paste, so you can do a little research and hopefully it will be more clear.

Sign up to request clarification or add additional context in comments.

1 Comment

But how can i then handle the interpolateProvider for the starting symbol? Do i need to rewrite them everytime again and again?

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.