把“作用范围”批量改为“作用域”
This commit is contained in:
parent
4400deeef8
commit
28fe7d848f
|
@ -397,7 +397,7 @@ a(id="countdown-tests")
|
|||
|
||||
The scope of the service instance is the parent component and its children. Components outside this component subtree have no access to the service or their communications.
|
||||
|
||||
该服务实例的作用范围被限制在父组件和其子组件内。这个组件子树之外的组件将无法访问该服务或者与它们通讯。
|
||||
该服务实例的作用域被限制在父组件和其子组件内。这个组件子树之外的组件将无法访问该服务或者与它们通讯。
|
||||
|
||||
This `MissionService` connects the `MissionControlComponent` to multiple `AstronautComponent` children.
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ include ../_util-fns
|
|||
|
||||
[Limit service scope to a component subtree](#service-scope)
|
||||
|
||||
[把服务作用范围限制到一个子组件树](#service-scope)
|
||||
[把服务作用域限制到一个子组件树](#service-scope)
|
||||
|
||||
[Multiple service instances (sandboxing)](#multiple-service-instances)
|
||||
|
||||
|
@ -303,7 +303,7 @@ figure.image-display
|
|||
:marked
|
||||
## Limit service scope to a component subtree
|
||||
|
||||
## 把服务作用范围限制到一个组件支树
|
||||
## 把服务作用域限制到一个组件支树
|
||||
|
||||
All injected service dependencies are singletons meaning that,
|
||||
for a given dependency injector ("injector"), there is only one instance of service.
|
||||
|
@ -334,7 +334,7 @@ figure.image-display
|
|||
by providing that service *at the sub-root component for that branch*.
|
||||
Here we provide the `HeroService` to the `HeroesBaseComponent` by listing it in the `providers` array:
|
||||
|
||||
通过*在组件树的子级根组件*中提供服务,可以把一个被注入服务的作用范围局限在应用程序结构中的某个*分支*中。
|
||||
通过*在组件树的子级根组件*中提供服务,可以把一个被注入服务的作用域局限在应用程序结构中的某个*分支*中。
|
||||
这里通过列入`providers`数组,在`HeroesBaseComponent`中提供了`HeroService`:
|
||||
|
||||
+makeExample('cb-dependency-injection/ts/app/sorted-heroes.component.ts','injection','app/sorted-heroes.component.ts (HeroesBaseComponent excerpt)')
|
||||
|
|
|
@ -322,7 +322,7 @@ include _util-fns
|
|||
that it decorates. None of the decorations shown here will "leak" to other
|
||||
classes appearing below it in the file.
|
||||
|
||||
一个装饰器的作用范围会被限制在它所装饰的东西上,这是一个语言级特性。在上面这个例子中,就算别的类在同一个文件中紧跟着上面的类也不会有任何装饰器“泄露”到其它类。
|
||||
一个装饰器的作用域会被限制在它所装饰的东西上,这是一个语言级特性。在上面这个例子中,就算别的类在同一个文件中紧跟着上面的类也不会有任何装饰器“泄露”到其它类。
|
||||
|
||||
.alert.is-important
|
||||
:marked
|
||||
|
|
|
@ -279,7 +279,7 @@ figure.image-display
|
|||
|
||||
但很明显,这个场景下我们不希望这样。我们希望每个组件都有它自己的`RestoreService`实例。
|
||||
在组件级别上定义(或重定义)一个提供商,将会为该组件创建一个新的服务实例。
|
||||
我们已经为`HeroEditComponent`制造了一种“私有”`RestoreService`单例,它的作用范围被局限在了该组件的实例及其子组件中。
|
||||
我们已经为`HeroEditComponent`制造了一种“私有”`RestoreService`单例,它的作用域被局限在了该组件的实例及其子组件中。
|
||||
|
||||
<!--
|
||||
## Advanced Dependency Injection in Angular 2
|
||||
|
|
|
@ -230,7 +230,7 @@ code-example(language="bash").
|
|||
When we assign styles to a component they are scoped to that specific component.
|
||||
Our styles will only apply to our `AppComponent` and won't "leak" to the outer HTML.
|
||||
|
||||
当我们把样式赋予一个组件时,它们的作用范围将仅限于该组件。
|
||||
当我们把样式赋予一个组件时,它们的作用域将仅限于该组件。
|
||||
即:此样式只会作用于这个`AppComponent`组件,而不会“泄露”到外部HTML中。
|
||||
|
||||
Our template for displaying the heroes should now look like this:
|
||||
|
|
Loading…
Reference in New Issue