0

I have a JS file with Angular controllers etc. that are used on lots, or many pages. It starts with the line:

var fb = angular.module( 'fb', ['fb.controllers','fb.directives','fb.services','ui.bootstrap'] );

The JS file also contains Angular controllers etc. that are used rarely, that depend on 'ui.bootstrap'.

What solutions are available to move my Angular code to separate JS files and only including the dependency 'ui.bootstrap' when I need it?

1 Answer 1

1

You are right, it is strongly recommended to separate such things and also to create one file per controller/directive/filter/etc.

Once you registered module you can use it in the other js files. Angular automatically resolve dependencies.

For example, in fb-controllers.js you register 'fb.controllers' module which depends on 'ui.bootstrap':

angular.module('fb.controllers', ['angular.ui']);

in fb-directives.js you register 'fb.directives' module which ot depends on 'ui.bootstrap':

angular.module('fb.directives', []);

then in app.js you register your main module with dependencies on other:

var fb = angular.module( 'fb', ['fb.controllers','fb.directives']);
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.