配置AngularJS模块 - 它是如何影响应用程序的其他模块? [英] Configuring AngularJS modules - how does it affect the other modules in the app?
问题描述
我有两个角模块, A
和 B
。 A
没有DEPS,某些配置和一些过滤器:
I have two Angular modules, A
and B
.
A
has no deps, some configurations and some filters:
angular.module('A', [])
.config(function ($httpProvider) {
// set common headers for $http requests
$httpProvider.defaults.headers.common = {...};
})
.filter('myFilter', function () {
// create a filter
});
B
取决于 A
,所以它是这样的东西:
B
depends on A
, so it goes something like:
angular.module('B', ['A'])...
我知道 B
根据 A
意味着我可以使用 myFilter
B
的意见里面。
I know that B
depending on A
means I can use myFilter
inside B
views.
现在的问题是:是否在 myFilter
福利code从 $ HTTP
通用报头我设置在配置内部()
的 A
模块的功能(因为 myFilter
属于 A
)?
The question is: does the code in myFilter
benefits from the $http
common headers I set inside the config()
function of the A
module (since myFilter
belongs to A
)?
和从 B
模块内部HTTP请求时,是常见的头我设置里面 A
的那些或者他们不会从里面 A
?
And when making HTTP requests from inside the B
module, are the common headers the ones I set inside A
or they are not affected from the configuration inside A
?
真到这两个问题使得足够的理智对我说:我的配置,我会过滤器的<$ C $内使用 A
模块中的一些常见的头C> A 模块提供,但我想我的方式同那些常见的头时,我是 B
模块内部;不过,当我 B里面
的意见,我希望能够使用 A
过滤器与具体的共同头
True to both the questions makes enough sense to me: I config some common headers in the A
module that I'll use inside the filters that the A
module provides, but I want those same common headers out of my way when I'm inside the B
module; still, when I'm inside B
views, I want to be able to use A
filters with their specific common headers.
推荐答案
在任何一个应用程序,无论你拉什么模块,所有的服务
,工厂
和提供商
为单身。
In any one app, no matter what modules you pull in, all services
, factories
and providers
are singletons.
您正在使用 $ httpProvider
,一个这样的单身......因此,由单身人士的本质,任何配置做一个提供商用于所有模块都受到影响
You're using the $httpProvider
, one such singleton... and therefore, by the very nature of singletons, any configuration done to a provider means all modules are affected.
这篇关于配置AngularJS模块 - 它是如何影响应用程序的其他模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!