父模块作为依赖项

Ba5*_*14n 9 javascript iframe angularjs

我的应用程序有一个角度模块:

var io = angular.module('IO_Operations', []);
Run Code Online (Sandbox Code Playgroud)


该模块还有一个服务来实现输入/输出的东西:

io.service('ioService', function () {
    var dataStore = {};

    return {
        pushData: function (key, value) {
            dataStore[key] = value;
        },
        getData: function (key) {
            return dataStore[key];
        }
    };
});
Run Code Online (Sandbox Code Playgroud)


后来我想将dataStore带有JSON 的变量存储在一个文件中作为对象.

现在我有一个iframe用标签显示一些内容,你可以称之为浏览器.


为了能够进行一些设置,我想在一个iframe中完成.为了将数据保存到文件,我需要调用IO_Service,在父应用程序中

在我的iframe中我有一个模块:

var settings = angular.module("settings", []);
Run Code Online (Sandbox Code Playgroud)

用控制器

settings.controller("MyController", function ($scope) { ... }
Run Code Online (Sandbox Code Playgroud)

所以我需要为父模块声明一个依赖项来使用它ioService来调用该pushData函数.

有没有人有一些提示让我意识到这一点?

Doc*_*ick 0

您应该做的就是让设置模块知道它依赖于 IO 操作模块,一旦完成,您就可以使用 IO 服务,就好像它在同一模块中一样,如下所示:

var settings = angular.module("settings", ["IO_Operations"]);

settings.controller("MyController", function ($scope, ioService) { ... }
Run Code Online (Sandbox Code Playgroud)