清理不必要的#{变量

This commit is contained in:
Zhicheng Wang 2017-04-15 16:13:16 +08:00
parent 3b9708283a
commit 473c688f70
4 changed files with 14 additions and 14 deletions

View File

@ -9,7 +9,7 @@
- var _Lang = 'TypeScript'; - var _Lang = 'TypeScript';
//- Simple "macros" used via interpolation in text: //- Simple "macros" used via interpolation in text:
//- e.g., the #{_priv}el variable has an `@Input` #{_decorator}. //- e.g., the el variable has an `@Input` #{_decorator}.
//- Use #{_decorator} whereever the word "decorator" is expected, provided it is not //- Use #{_decorator} whereever the word "decorator" is expected, provided it is not
//- preceded by the article "a". (E.g., will be "annotation" for Dart) //- preceded by the article "a". (E.g., will be "annotation" for Dart)

View File

@ -332,7 +332,7 @@ figure.image-display
which you declare and initialize in the constructor. which you declare and initialize in the constructor.
这些处理器委托给了一个辅助方法它用于为DOM元素设置颜色`#{_priv}el`就是你在构造器中声明和初始化过的。 这些处理器委托给了一个辅助方法它用于为DOM元素设置颜色`el`就是你在构造器中声明和初始化过的。
+makeExcerpt('src/app/highlight.directive.2.ts (constructor)', 'ctor') +makeExcerpt('src/app/highlight.directive.2.ts (constructor)', 'ctor')
:marked :marked

View File

@ -173,7 +173,7 @@ block includes
That makes `Car` brittle. That makes `Car` brittle.
如果`Engine`类升级了,它的构造函数要求传入一个参数,这该怎么办? 如果`Engine`类升级了,它的构造函数要求传入一个参数,这该怎么办?
这个`Car`类就被破坏了,在把创建引擎的代码重写为`#{prefix}engine = new Engine(theNewParameter)`之前,它都是坏的。 这个`Car`类就被破坏了,在把创建引擎的代码重写为`this.engine = new Engine(theNewParameter)`之前,它都是坏的。
当第一次写`Car`类时,我们不关心`Engine`构造函数的参数,现在也不想关心。 当第一次写`Car`类时,我们不关心`Engine`构造函数的参数,现在也不想关心。
但是,当`Engine`类的定义发生变化时,就不得不在乎了,`Car`类也不得不跟着改变。 但是,当`Engine`类的定义发生变化时,就不得不在乎了,`Car`类也不得不跟着改变。
这就会让`Car`类过于脆弱。 这就会让`Car`类过于脆弱。
@ -737,7 +737,7 @@ a#injectable
error when trying to instantiate a class that is not marked as error when trying to instantiate a class that is not marked as
`@Injectable()`. `@Injectable()`.
**<a href="#{injUrl}">@Injectable()</a>** 标识一个类可以被注入器实例化。 **<a href="../api/core/index/Injectable-decorator.html">@Injectable()</a>** 标识一个类可以被注入器实例化。
通常,在试图实例化没有被标识为`@Injectable()`的类时,注入器会报错。 通常,在试图实例化没有被标识为`@Injectable()`的类时,注入器会报错。
.l-sub-section .l-sub-section
@ -787,7 +787,7 @@ a#injectable
identify a class as a target for instantiation by an injector. identify a class as a target for instantiation by an injector.
我们**可以**添加它。但是没有必要,因为`HerosComponent`已经有`@Component`装饰器了, 我们**可以**添加它。但是没有必要,因为`HerosComponent`已经有`@Component`装饰器了,
`@Component`(和随后将会学到的`@Directive`和`@Pipe`一样)是 <a href="#{injUrl}">Injectable</a> 的子类型。 `@Component`(和随后将会学到的`@Directive`和`@Pipe`一样)是 <a href="../api/core/index/Injectable-decorator.html">Injectable</a> 的子类型。
实际上,正是这些`Injectable`装饰器是把一个类标识为注入器实例化的目标。 实际上,正是这些`Injectable`装饰器是把一个类标识为注入器实例化的目标。
.l-sub-section .l-sub-section
@ -815,7 +815,7 @@ a#injectable
<a href="../api/core/index/Injectable-decorator.html">@Injectable()</a> decorator <a href="../api/core/index/Injectable-decorator.html">@Injectable()</a> decorator
to make the intent clear. to make the intent clear.
当然,任何装饰器都会触发这个效果,用 <a href="#{injUrl}">Injectable</a> 来标识服务 当然,任何装饰器都会触发这个效果,用 <a href="../api/core/index/Injectable-decorator.html">Injectable</a> 来标识服务
只是让这一意图更明显。 只是让这一意图更明显。
.callout.is-critical .callout.is-critical
@ -855,7 +855,7 @@ a#injectable
so put it in the project's `app` folder and so put it in the project's `app` folder and
register it in the `providers` array of the application module, `AppModule`. register it in the `providers` array of the application module, `AppModule`.
应用的每个角落都可能需要日志服务,所以把它放到项目的`#{_appDir}`目录, 应用的每个角落都可能需要日志服务,所以把它放到项目的`app`目录,
并在应用模块`AppModule`的元数据`providers`数组里注册它。 并在应用模块`AppModule`的元数据`providers`数组里注册它。
+makeExcerpt('src/app/providers.component.ts (excerpt)', 'providers-logger','src/app/app.module.ts') +makeExcerpt('src/app/providers.component.ts (excerpt)', 'providers-logger','src/app/app.module.ts')
@ -910,7 +910,7 @@ code-example(format="nocode").
The `Logger` class itself is an obvious and natural provider. The `Logger` class itself is an obvious and natural provider.
But it's not the only way. But it's not the only way.
有很多方式可以*提供*一些#{implementsCn} `Logger`类的东西。 有很多方式可以*提供*一些实现 `Logger`类的东西。
`Logger`类本身是一个显而易见而且自然而然的提供商。 `Logger`类本身是一个显而易见而且自然而然的提供商。
但它不是唯一的选项。 但它不是唯一的选项。
@ -1170,9 +1170,9 @@ a#value-provider
This extra step makes the factory provider reusable. This extra step makes the factory provider reusable.
You can register the `HeroService` with this variable wherever you need it. You can register the `HeroService` with this variable wherever you need it.
注意,我们在#{anexportedvarCn}中捕获了这个工厂提供商:`heroServiceProvider`。 注意,我们在一个导出的变量中捕获了这个工厂提供商:`heroServiceProvider`。
这个额外的步骤让工厂提供商可被复用。 这个额外的步骤让工厂提供商可被复用。
无论哪里需要,都可以使用这个#{variableCn}注册`HeroService`。 无论哪里需要,都可以使用这个变量注册`HeroService`。
In this sample, you need it only in the `HeroesComponent`, In this sample, you need it only in the `HeroesComponent`,
where it replaces the previous `HeroService` registration in the metadata `providers` array. where it replaces the previous `HeroService` registration in the metadata `providers` array.

View File

@ -211,7 +211,7 @@ block demos-list
:marked :marked
Before you can use the `Http` client, you need to register it as a service provider with the dependency injection system. Before you can use the `Http` client, you need to register it as a service provider with the dependency injection system.
要想使用`#{_Http}`客户端,你需要先通过依赖注入系统把它注册成一个服务提供商。 要想使用`Http`客户端,你需要先通过依赖注入系统把它注册成一个服务提供商。
.l-sub-section .l-sub-section
:marked :marked
@ -573,7 +573,7 @@ a#no-return-response-object
which means that the request won't go out until something *subscribes* to the Observable. which means that the request won't go out until something *subscribes* to the Observable.
That *something* is the [HeroListComponent](#subscribe). That *something* is the [HeroListComponent](#subscribe).
`#{_priv}http.get`**仍然没有发送请求!**这是因为可观察对象是 `http.get`**仍然没有发送请求!**这是因为可观察对象是
[*冷的*](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/creating.md#cold-vs-hot-observables) [*冷的*](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/creating.md#cold-vs-hot-observables)
也就是说,只有当某人*订阅*了这个可观察对象时,这个请求才会被发出。 也就是说,只有当某人*订阅*了这个可观察对象时,这个请求才会被发出。
这个场景中的*某人*就是[HeroListComponent](#subscribe)。 这个场景中的*某人*就是[HeroListComponent](#subscribe)。
@ -622,7 +622,7 @@ block hlc-error-handling
the `subscribe` function has a second function parameter to handle the error message. the `subscribe` function has a second function parameter to handle the error message.
It sets an `errorMessage` variable that's bound conditionally in the `HeroListComponent` template. It sets an `errorMessage` variable that's bound conditionally in the `HeroListComponent` template.
回到`HeroListComponent`,这里我们调用了`#{_priv}heroService.getHeroes()`。我们提供了`subscribe`函数的第二个参数来处理错误信息。 回到`HeroListComponent`,这里我们调用了`heroService.getHeroes()`。我们提供了`subscribe`函数的第二个参数来处理错误信息。
它设置了一个`errorMessage`变量,被有条件的绑定到了`HeroListComponent`模板中。 它设置了一个`errorMessage`变量,被有条件的绑定到了`HeroListComponent`模板中。
+makeExample('server-communication/ts/src/app/toh/hero-list.component.ts', 'getHeroes', 'src/app/toh/hero-list.component.ts (getHeroes)')(format=".") +makeExample('server-communication/ts/src/app/toh/hero-list.component.ts', 'getHeroes', 'src/app/toh/hero-list.component.ts (getHeroes)')(format=".")
@ -886,7 +886,7 @@ block wikipedia-jsonp+
All other HTTP methods throw an error because `JSONP` is a read-only facility. All other HTTP methods throw an error because `JSONP` is a read-only facility.
Wikipedia 提供了一个现代的`CORS` API和一个传统的`JSONP`搜索 API。在这个例子中我们使用后者。 Wikipedia 提供了一个现代的`CORS` API和一个传统的`JSONP`搜索 API。在这个例子中我们使用后者。
Angular 的`Jsonp`服务不但通过 JSONP 扩展了`#{_Http}`服务,而且限制我们只能用`GET`请求。 Angular 的`Jsonp`服务不但通过 JSONP 扩展了`Http`服务,而且限制我们只能用`GET`请求。
尝试调用所有其它 HTTP 方法都将抛出一个错误,因为 JSONP 是只读的。 尝试调用所有其它 HTTP 方法都将抛出一个错误,因为 JSONP 是只读的。
As always, wrap the interaction with an Angular data access client service inside a dedicated service, here called `WikipediaService`. As always, wrap the interaction with an Angular data access client service inside a dedicated service, here called `WikipediaService`.