Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将子模块访问权授予父提供程序_Javascript_Angularjs_Module - Fatal编程技术网

Javascript 将子模块访问权授予父提供程序

Javascript 将子模块访问权授予父提供程序,javascript,angularjs,module,Javascript,Angularjs,Module,我正在尝试设置一个将在每个模块上单独调用的提供程序,以便它可以访问该提供程序 我有一个父母ng应用程序引导周围的一切,然后在里面我可以调用单独的模块。我最初的方法是在父应用程序模块中有一个工厂(这非常有效),但是我希望每个模块都能够将自己的.config文件发送给这个提供程序,这样它每次都可以发送自己的变量给提供程序处理。我的问题是能否让子模块访问父提供程序 因此,我有我的父应用程序和提供商,如下所示: angular. module('urlTesting', [ 'urlTesting.

我正在尝试设置一个将在每个模块上单独调用的提供程序,以便它可以访问该提供程序

我有一个父母ng应用程序引导周围的一切,然后在里面我可以调用单独的模块。我最初的方法是在父应用程序模块中有一个工厂(这非常有效),但是我希望每个模块都能够将自己的.config文件发送给这个提供程序,这样它每次都可以发送自己的变量给提供程序处理。我的问题是能否让子模块访问父提供程序

因此,我有我的父应用程序和提供商,如下所示:

 angular.
 module('urlTesting', [
'urlTesting.moduleOne',
'urlTesting.moduleTwo'
])
.provider('statepls', function() { 

});
它通过ng应用程序和子模块(模块1和模块2被注入)引导到身体上

然后在子模块中,我像这样注入父模块

 angular.
  module('urlTesting.moduleOne', [
    'urlTesting.moduleOneCtrl',
    'moduleOne.directive',
    'urlTesting'
  ]).config(function(){

});
我可以使用父模块中的工厂,但是似乎我不能使用配置来设置一些变量,就像我尝试这样做时:

   angular.
  module('urlTesting.moduleOne', [
'urlTesting.moduleOneCtrl',
'moduleOne.directive',
'urlTesting'
 ]).config(function(stateplsProvider){

 });
我得到一份工作-

  Unknown provider: stateplsProvider
因此,在父模块的运行阶段之前,它可能看不到提供程序?或者也许我注射这些是错误的


我的目标是在父模块上设置一个提供者,所有后续模块都可以访问该提供者,并且能够在每个模块中使用.config设置一些内容。我需要一些帮助来解决这个问题,我似乎无法让它工作。谢谢你的阅读

您确定没有收到循环引用异常吗?我看到您正在子模块上导入父模块。在子模块中,您只需请求在配置中注入父提供程序。如果父模块尚未启动(如测试),则应在模块中提供默认的提供程序实现。更好的设计可能是创建具有提供程序的第三个模块,并将其注入到其他两个模块中。@mxa055我最后就是这么做的!