I have the following in app.js
config = angular.module('config', [])
.constant('Constants', {
Car: 'BMW',
Phone: 'G4'
});
services = angular.module('services', ['config']);
controllers = angular.module('controllers', ['config', 'services']);
app = angular.module('myApp', ['config', 'controllers']);
I want to move the "config" module definition to a separate file as I'm expecting it to grow bigger.
Is it possible to move the below portion to a separate file:
config = angular.module('config', [])
.constant('Constants', {
Car: 'BMW',
Phone: 'G4'
});
asked Aug 13, 2015 at 12:36
saravana_pc
2,70711 gold badges47 silver badges68 bronze badges
2 Answers 2
There is no problem with doing that.
You just need to make sure the config module will be loaded before the app module
answered Aug 13, 2015 at 12:41
Deblaton Jean-Philippe
11.4k4 gold badges53 silver badges68 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You've chosen very bad structure for your angular app. Please check this url https://scotch.io/tutorials/angularjs-best-practices-directory-structure
And about your question. Instead of using caching variables just do next thing:
file0: angular.module('config',[]);
file1: angular.module('config').constant('Constants', {Car: 'BMW', Phone: 'G4'});
file2: angular.module('config').constant('Constants2', {Car: 'BMW', Phone: 'G4'});
answered Aug 13, 2015 at 12:40
sonnenhaft
1,6471 gold badge13 silver badges15 bronze badges
2 Comments
saravana_pc
I've not mentioned anything about my directory structure. It exactly matches the best practices.
Joe Lloyd
We can see your structure from the way everything has been declared, vlad is tottaly correct imo. the link he provided is very good aswell.
default
Is it possible... shouldn't you just try it first? If you did what problems arose?