From 0ed2ae71e10e9ee1fe985fd7f792df87abe63600 Mon Sep 17 00:00:00 2001 From: Zhicheng Wang Date: Mon, 12 Mar 2018 14:36:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BF=BB=E8=AF=91=E3=80=8A=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E3=80=8B=E5=92=8C=E3=80=8A=E5=BC=95=E5=AF=BC=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E3=80=8B=E4=B8=AD=E9=81=97=E6=BC=8F=E7=9A=84=E9=83=A8?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guide/dependency-injection-pattern.md | 21 +++++++++++++++++-- aio/content/navigation.json | 4 ++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/aio/content/guide/dependency-injection-pattern.md b/aio/content/guide/dependency-injection-pattern.md index 8667b15d75..eab10ae224 100644 --- a/aio/content/guide/dependency-injection-pattern.md +++ b/aio/content/guide/dependency-injection-pattern.md @@ -1,16 +1,27 @@ # The Dependency Injection pattern +# 依赖注入(Dependency injection)模式 + **Dependency injection** is an important application design pattern. It's used so widely that almost everyone just calls it _DI_. +**依赖注入**是一个很重要的设计模式。 +它使用得非常广泛,以至于几乎每个人都把它简称为 *DI* 。 + Angular has its own dependency injection framework, and you really can't build an Angular application without it. +Angular 有自己的依赖注入框架,离开它,你几乎没办法构建出 Angular 应用。 + 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 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 } ## Why dependency injection? @@ -30,6 +41,10 @@ The `Car` class creates everything it needs inside its constructor. What's the problem? 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, the `Car` constructor instantiates its own copies from the very specific classes `Engine` and `Tires`. @@ -100,10 +115,10 @@ How can you make `Car` more robust, flexible, and testable? {@a ctor-injection} -答案非常简单。把`Car`的构造函数改造成使用 DI 的版本: - That's super easy. Change the `Car` constructor to a version with DI: +答案非常简单。把`Car`的构造函数改造成使用 DI 的版本: + @@ -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, turn to the [Angular Dependency Injection](guide/dependency-injection) guide to see how it is implemented in Angular. + +现在,你知道什么是依赖注入以及它有什么优点了吧?那就请到 [Angular 依赖注入](guide/dependency-injection) 中去看看它在 Angular 中是如何实现的。 diff --git a/aio/content/navigation.json b/aio/content/navigation.json index bb40ea706c..e7b0ba1df0 100644 --- a/aio/content/navigation.json +++ b/aio/content/navigation.json @@ -298,8 +298,8 @@ "children": [ { "url": "guide/dependency-injection-pattern", - "title": "The Dependency Injection pattern", - "tooltip": "Learn about the dependency injection pattern behind the Angular DI system." + "title": "依赖注入模式", + "tooltip": "学习 Angular 依赖注入系统背后的依赖注入模式" }, { "url": "guide/dependency-injection",