Javascript 角度-在多个文件中定义模块
我在app.js中有以下内容Javascript 角度-在多个文件中定义模块,javascript,angularjs,coffeescript,Javascript,Angularjs,Coffeescript,我在app.js中有以下内容 config = angular.module('config', []) .constant('Constants', { Car: 'BMW', Phone: 'G4' }); services = angular.module('services', ['config']); controllers = angular.module('controllers', ['config', 'services']); app =
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']);
我希望将“config”模块定义移动到一个单独的文件中,因为我希望它会变得更大
是否可以将以下部分移动到单独的文件中:
config = angular.module('config', [])
.constant('Constants', {
Car: 'BMW',
Phone: 'G4'
});
您为angular应用程序选择了非常糟糕的结构。请检查此url 关于你的问题。不要使用缓存变量,只需执行以下操作:
file0: angular.module('config',[]);
file1: angular.module('config').constant('Constants', {Car: 'BMW', Phone: 'G4'});
file2: angular.module('config').constant('Constants2', {Car: 'BMW', Phone: 'G4'});
这样做没有问题
您只需确保在加载应用程序模块之前加载配置模块您无法更改常量值…可能有许多文件..不清楚确切的问题是什么或您在问什么。但是,应该将模块分组为功能而不是组件。为了清晰起见,我编辑了该问题。
是否可能
。。。你不应该先试试吗?如果您这样做了,会出现什么问题?@charlietfl,因为我们不能在javascript中“包含”其他文件。我没有提到我的目录结构。它完全符合最佳实践。我们可以从声明所有内容的方式看出您的结构,在我看来,vlad是完全正确的。他提供的链接也非常好。