角,如何结合模块



i有一个页面 html1.html with Module MOD1

[html1.html]
<html lang="en" ng-app="mod1">
...
<script src="scripts/services/Data.js"></script>

data.js mod1

的工厂
[Data.js]
angular.module('mod1').factory('Data',[function(){
...
}]);

然后,我的第二页 html2.html 与Module mod2 ,我也想使用相同的工厂,而不是之前

[html2.html]
<html lang="en" ng-app="mod2">
...
<script src="scripts/services/Data.js"></script>
<script src="scripts/services/Train.js"></script>

train.js mod2 的工厂以下

[Train.js]
var mod2 = angular.module('mod2',[angular.module('mod1')]);
mod2.factory('Train',[function(){
...
}]);

但Angular找不到模块 mod1 。我想念什么?

* html1.html html2.html 是来自同一电子应用程序的渲染器

模块依赖项由名称指定,因此在Train.js

angular.module('mod2', ['mod1'])

您只需要包括定义mod1的文件,即具有

的文件
angular.module('mod1', ['maybe', 'some', 'deps', 'here'])

您将该文件包括在html2.html中,以及提供商的任何其他文件(例如Data.js),该模块中的所有内容都将可用。

大概您已经定义了Data.js或其他文件中的模块mod1。在Train.js中再次定义它,用新的,空的名称覆盖了注册名称。

最新更新