fix: 翻译《表单》和《引导启动》中遗漏的部分
This commit is contained in:
parent
964cefaeea
commit
0ed2ae71e1
|
@ -1,16 +1,27 @@
|
||||||
# The Dependency Injection pattern
|
# The Dependency Injection pattern
|
||||||
|
|
||||||
|
# 依赖注入(Dependency injection)模式
|
||||||
|
|
||||||
**Dependency injection** is an important application design pattern.
|
**Dependency injection** is an important application design pattern.
|
||||||
It's used so widely that almost everyone just calls it _DI_.
|
It's used so widely that almost everyone just calls it _DI_.
|
||||||
|
|
||||||
|
**依赖注入**是一个很重要的设计模式。
|
||||||
|
它使用得非常广泛,以至于几乎每个人都把它简称为 *DI* 。
|
||||||
|
|
||||||
Angular has its own dependency injection framework, and
|
Angular has its own dependency injection framework, and
|
||||||
you really can't build an Angular application without it.
|
you really can't build an Angular application without it.
|
||||||
|
|
||||||
|
Angular 有自己的依赖注入框架,离开它,你几乎没办法构建出 Angular 应用。
|
||||||
|
|
||||||
This page covers what DI is and why it's useful.
|
This page covers what DI is and why it's useful.
|
||||||
|
|
||||||
|
本页会告诉你 DI 是什么,以及为什么它很有用。
|
||||||
|
|
||||||
When you've learned the general pattern, you're ready to turn to
|
When you've learned the general pattern, you're ready to turn to
|
||||||
the [Angular Dependency Injection](guide/dependency-injection) guide to see how it works in an Angular app.
|
the [Angular Dependency Injection](guide/dependency-injection) guide to see how it works in an Angular app.
|
||||||
|
|
||||||
|
当你学会了这种通用的模式之后,就可以转到 [Angular 依赖注入](guide/dependency-injection) 中去看看它在 Angular 应用中的工作原理了。
|
||||||
|
|
||||||
{@a why-di }
|
{@a why-di }
|
||||||
|
|
||||||
## Why dependency injection?
|
## Why dependency injection?
|
||||||
|
@ -30,6 +41,10 @@ The `Car` class creates everything it needs inside its constructor.
|
||||||
What's the problem?
|
What's the problem?
|
||||||
The problem is that the `Car` class is brittle, inflexible, and hard to test.
|
The problem is that the `Car` class is brittle, inflexible, and hard to test.
|
||||||
|
|
||||||
|
`Car` 类在自己的构造函数中创建了它所需的一切。
|
||||||
|
这样做有什么问题?
|
||||||
|
问题在于 `Car` 类是脆弱、不灵活以及难于测试的。
|
||||||
|
|
||||||
This `Car` needs an engine and tires. Instead of asking for them,
|
This `Car` needs an engine and tires. Instead of asking for them,
|
||||||
the `Car` constructor instantiates its own copies from
|
the `Car` constructor instantiates its own copies from
|
||||||
the very specific classes `Engine` and `Tires`.
|
the very specific classes `Engine` and `Tires`.
|
||||||
|
@ -100,10 +115,10 @@ How can you make `Car` more robust, flexible, and testable?
|
||||||
|
|
||||||
{@a ctor-injection}
|
{@a ctor-injection}
|
||||||
|
|
||||||
答案非常简单。把`Car`的构造函数改造成使用 DI 的版本:
|
|
||||||
|
|
||||||
That's super easy. Change the `Car` constructor to a version with DI:
|
That's super easy. Change the `Car` constructor to a version with DI:
|
||||||
|
|
||||||
|
答案非常简单。把`Car`的构造函数改造成使用 DI 的版本:
|
||||||
|
|
||||||
<code-tabs>
|
<code-tabs>
|
||||||
|
|
||||||
<code-pane title="src/app/car/car.ts (excerpt with DI)" path="dependency-injection/src/app/car/car.ts" region="car-ctor">
|
<code-pane title="src/app/car/car.ts (excerpt with DI)" path="dependency-injection/src/app/car/car.ts" region="car-ctor">
|
||||||
|
@ -257,3 +272,5 @@ This is what a **dependency injection framework** is all about.
|
||||||
|
|
||||||
Now that you know what dependency injection is and appreciate its benefits,
|
Now that you know what dependency injection is and appreciate its benefits,
|
||||||
turn to the [Angular Dependency Injection](guide/dependency-injection) guide to see how it is implemented in Angular.
|
turn to the [Angular Dependency Injection](guide/dependency-injection) guide to see how it is implemented in Angular.
|
||||||
|
|
||||||
|
现在,你知道什么是依赖注入以及它有什么优点了吧?那就请到 [Angular 依赖注入](guide/dependency-injection) 中去看看它在 Angular 中是如何实现的。
|
||||||
|
|
|
@ -298,8 +298,8 @@
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"url": "guide/dependency-injection-pattern",
|
"url": "guide/dependency-injection-pattern",
|
||||||
"title": "The Dependency Injection pattern",
|
"title": "依赖注入模式",
|
||||||
"tooltip": "Learn about the dependency injection pattern behind the Angular DI system."
|
"tooltip": "学习 Angular 依赖注入系统背后的依赖注入模式"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "guide/dependency-injection",
|
"url": "guide/dependency-injection",
|
||||||
|
|
Loading…
Reference in New Issue