diff --git a/aio/tools/translator/dict-latest.json b/aio/tools/translator/dict-latest.json index 3f506df9bb..104980d623 100644 --- a/aio/tools/translator/dict-latest.json +++ b/aio/tools/translator/dict-latest.json @@ -42,9 +42,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/_fragments/glossary-t2.md" }, { - "key": "#ANGULARJSTOANGULARQUICKREFERENCE", - "original": "# AngularJS to Angular Quick Reference", - "translation": "# 从 AngularJS 到 Angular 快速参考", + "key": "#ANGULARJSTOANGULARCONCEPTS:QUICKREFERENCE", + "original": "# AngularJS to Angular Concepts: Quick Reference", + "translation": "# 关于AngularJS 与 Angular 概念的快速参考", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md" }, { @@ -990,9 +990,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md" }, { - "key": "WITHTHEANGULARCLIYOUCANCONFIGUREYOURGLOBALSTYLESINTHEANGULARCLIJSONFILEYOUCANRENAMETHEEXTENSIONTOSCSSTOUSESASS", - "original": "With the Angular CLI, you can configure your global styles in the `.angular-cli.json` file.\n You can rename the extension to `.scss` to use sass.", - "translation": "使用 Angular CLI,你可以在 `.angular-cli.json` 文件中配置全局样式。\n 也可以把扩展名改为 `.scss` 来使用 sass。", + "key": "WITHTHEANGULARCLIYOUCANCONFIGUREYOURGLOBALSTYLESINTHEANGULARJSONFILEYOUCANRENAMETHEEXTENSIONTOSCSSTOUSESASS", + "original": "With the Angular CLI, you can configure your global styles in the `angular.json` file.\n You can rename the extension to `.scss` to use sass.", + "translation": "使用 Angular CLI,你可以在 `angular.json` 文件中配置全局样式。\n 也可以把扩展名改为 `.scss` 来使用 sass。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md" }, { @@ -1728,8 +1728,8 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, { - "key": "METADATAJSONFILESCONTAININFOMRATIONNEEDEDBYTHETEMPLATECOMPILERFROMATSFILETHATISNOTINCLUDEDINTHEDTSFILEPRODUCEDBYTHETYPESCRIPTCOMPILERTHISINFORMATIONCONTAINSFOREXAMPLETHECONTENTOFANNOTATIONSSUCHASACOMPONENTSTEMPLATEWHICHTYPESCRIPTEMITSTOTHEJSFILEBUTNOTTOTHEDTSFILE", - "original": "`.metadata.json` files contain infomration needed by the template compiler from a `.ts`\nfile that is not included in the `.d.ts` file produced by the TypeScript compiler. This information contains,\nfor example, the content of annotations (such as a component's template) which TypeScript\nemits to the `.js` file but not to the `.d.ts` file.", + "key": "METADATAJSONFILESCONTAININFORMATIONNEEDEDBYTHETEMPLATECOMPILERFROMATSFILETHATISNOTINCLUDEDINTHEDTSFILEPRODUCEDBYTHETYPESCRIPTCOMPILERTHISINFORMATIONCONTAINSFOREXAMPLETHECONTENTOFANNOTATIONSSUCHASACOMPONENTSTEMPLATEWHICHTYPESCRIPTEMITSTOTHEJSFILEBUTNOTTOTHEDTSFILE", + "original": "`.metadata.json` files contain information needed by the template compiler from a `.ts`\nfile that is not included in the `.d.ts` file produced by the TypeScript compiler. This information contains,\nfor example, the content of annotations (such as a component's template) which TypeScript\nemits to the `.js` file but not to the `.d.ts` file.", "translation": "`.metadata.json` 文件中包含模板编译器所需的信息,这些信息来自于 `.ts` 文件中,但是没有包含在由 TypeScript 编译器生成的 `.d.ts` 文件中。\n比如,这个信息包括 TypeScript 发出的注解内容(如组件的模板),TypeScript 把它生成到了 `.js` 文件中,但是没有生成到 `.d.ts` 文件中。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, @@ -1747,8 +1747,8 @@ }, { "key": "THISOPTIONTELLSTHETEMPLATECOMPILERTOREPORTANERRORTOTHEMETADATAJSONFILEIFSKIPMETADATAEMITISFALSETHISOPTIONISFALSEBYDEFAULTTHISSHOULDONLYBEUSEDWHENSKIPMETADATAEMITISFALSEANDSKIPTEMPLATECODEGENISTRUE", - "original": "This option tells the template compiler to report an error to the `.metadata.json`\nfile if `\"skipMetadataEmit\"` is `false` . This option is `false` by default. This should only be used when `\"skipMetadataEmit\"` is `false` and `\"skipTemplateCodeGen\"` is `true`.", - "translation": "这个选项告诉模板编译器如果 `\"skipMetadataEmit\"` 为 `false`,那就把错误信息汇报到 `.metadata.json` 中。\n只有当 `\"skipMetadataEmit\"` 为 `false` 且 `\"skipTemplateCodeGen\"` 为 `true` 时才应该使用这个选项。", + "original": "This option tells the template compiler to report an error to the `.metadata.json`\nfile if `\"skipMetadataEmit\"` is `false` . This option is `false` by default. This should only be used when `\"skipMetadataEmit\"` is `false` and `\"skipTemplateCodegen\"` is `true`.", + "translation": "这个选项告诉模板编译器如果 `\"skipMetadataEmit\"` 为 `false`,那就把错误信息汇报到 `.metadata.json` 中。\n只有当 `\"skipMetadataEmit\"` 为 `false` 且 `\"skipTemplateCodegen\"` 为 `true` 时才应该使用这个选项。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, { @@ -1812,9 +1812,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, { - "key": "THISOPTIONTELLSTHECOMPILERTOENABLETHEBINDINGEXPRESSIONVALIDATION#BINDINGEXPRESIONVALIDATIONPHASEOFTHETEMPLATECOMPILERWHICHUSESTYPESCRIPTTOVALIDATEBINDINGEXPRESSIONS", - "original": "This option tells the compiler to enable the [binding expression validation](#binding-expresion-validation)\nphase of the template compiler which uses TypeScript to validate binding expressions.", - "translation": "该选项告诉编译器要为模板编译器启用[绑定表达式验证](#binding-expresion-validation)阶段,它会使用 TypeScript 来验证绑定表达式。", + "key": "THISOPTIONTELLSTHECOMPILERTOENABLETHEBINDINGEXPRESSIONVALIDATION#BINDINGEXPRESSIONVALIDATIONPHASEOFTHETEMPLATECOMPILERWHICHUSESTYPESCRIPTTOVALIDATEBINDINGEXPRESSIONS", + "original": "This option tells the compiler to enable the [binding expression validation](#binding-expression-validation)\nphase of the template compiler which uses TypeScript to validate binding expressions.", + "translation": "该选项告诉编译器要为模板编译器启用[绑定表达式验证](#binding-expression-validation)阶段,它会使用 TypeScript 来验证绑定表达式。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, { @@ -2088,8 +2088,8 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, { - "key": "BEGINNINGINVERSION5THECOMPILERAUTOMATICALLYPERFORMSTHISREWRITTINGWHILEEMITTINGTHEJSFILE", - "original": "Beginning in version 5, the compiler automatically performs this rewritting while emitting the `.js` file.", + "key": "BEGINNINGINVERSION5THECOMPILERAUTOMATICALLYPERFORMSTHISREWRITINGWHILEEMITTINGTHEJSFILE", + "original": "Beginning in version 5, the compiler automatically performs this rewriting while emitting the `.js` file.", "translation": "从 Angular v5 开始,编译器会在生成 `.js` 文件时自动执行这种改写。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, @@ -2400,8 +2400,8 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, { - "key": "THECOMPILERENCOUNTEREDANEXPRESSIONITDIDNTUNDERSTANDWHILEEVALUTATINGANGULARMETADATA", - "original": "The compiler encountered an expression it didn't understand while evalutating Angular metadata.", + "key": "THECOMPILERENCOUNTEREDANEXPRESSIONITDIDNTUNDERSTANDWHILEEVALUATINGANGULARMETADATA", + "original": "The compiler encountered an expression it didn't understand while evaluating Angular metadata.", "translation": "编译器在对 Angular 元数据求值时遇到了一个它不能理解的表达式。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, @@ -2628,8 +2628,8 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, { - "key": "THISCANHAPPENIFYOUREFERTOANAMBIENTTYPEFOREXAMPLETHEWINDOWTYPEISANAMBIANTTYPEDECLAREDINTHEGLOBALDTSFILE", - "original": "This can happen if you refer to an ambient type.\nFor example, the `Window` type is an ambiant type declared in the global `.d.ts` file.", + "key": "THISCANHAPPENIFYOUREFERTOANAMBIENTTYPEFOREXAMPLETHEWINDOWTYPEISANAMBIENTTYPEDECLAREDINTHEGLOBALDTSFILE", + "original": "This can happen if you refer to an ambient type.\nFor example, the `Window` type is an ambient type declared in the global `.d.ts` file.", "translation": "这通常会发生在你引用环境类型时。\n比如,`Window` 类型就是在全局 `.d.ts` 文件中声明的环境类型。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, @@ -2640,8 +2640,8 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, { - "key": "TYPESCRIPTUNDERSTANDSAMBIANTTYPESSOYOUDONTIMPORTTHEMTHEANGULARCOMPILERDOESNOTUNDERSTANDATYPETHATYOUNEGLECTTOEXPORTORIMPORT", - "original": "TypeScript understands ambiant types so you don't import them.\nThe Angular compiler does not understand a type that you neglect to export or import.", + "key": "TYPESCRIPTUNDERSTANDSAMBIENTTYPESSOYOUDONTIMPORTTHEMTHEANGULARCOMPILERDOESNOTUNDERSTANDATYPETHATYOUNEGLECTTOEXPORTORIMPORT", + "original": "TypeScript understands ambient types so you don't import them.\nThe Angular compiler does not understand a type that you neglect to export or import.", "translation": "TypeScript 能理解这些环境类型,所以你不用导入它们。\n但 Angular 编译器不理解你没有导入或导出过的类型。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, @@ -2658,14 +2658,14 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, { - "key": "IFYOUMUSTINJECTANINSTANCEOFANAMBIANTTYPEYOUCANFINESSETHEPROBLEMINFOURSTEPS:", - "original": "If you must inject an instance of an ambiant type,\nyou can finesse the problem in four steps:", + "key": "IFYOUMUSTINJECTANINSTANCEOFANAMBIENTTYPEYOUCANFINESSETHEPROBLEMINFOURSTEPS:", + "original": "If you must inject an instance of an ambient type,\nyou can finesse the problem in four steps:", "translation": "如果你必须注入某个环境类型的实例,可以用以下四步来巧妙解决这个问题:", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, { - "key": "1CREATEANINJECTIONTOKENFORANINSTANCEOFTHEAMBIANTTYPE", - "original": "1. Create an injection token for an instance of the ambiant type.", + "key": "1CREATEANINJECTIONTOKENFORANINSTANCEOFTHEAMBIENTTYPE", + "original": "1. Create an injection token for an instance of the ambient type.", "translation": "为环境类型的实例创建一个注入令牌。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, @@ -2796,8 +2796,8 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, { - "key": "INTHEVALIDATIONPHASETHEANGULARTEMPLATECOMPILERUSESTHETYPESCRIPTCOMPILERTOVALIDATETHEBINDINGEXPRESSIONSINTEMPLATESENABLETHISPHASEEXPLICITYBYADDINGTHECOMPILEROPTIONFULLTEMPLATETYPECHECKINTHEANGULARCOMPILEROPTIONSOFTHEPROJECTSTSCONFIGJSONSEEANGULARCOMPILEROPTIONS#COMPILEROPTIONS", - "original": "In the validation phase, the Angular template compiler uses the TypeScript compiler to validate the\n binding expressions in templates. Enable this phase explicity by adding the compiler\n option `\"fullTemplateTypeCheck\"` in the `\"angularCompilerOptions\"` of the project's `tsconfig.json` (see\n [Angular Compiler Options](#compiler-options)).", + "key": "INTHEVALIDATIONPHASETHEANGULARTEMPLATECOMPILERUSESTHETYPESCRIPTCOMPILERTOVALIDATETHEBINDINGEXPRESSIONSINTEMPLATESENABLETHISPHASEEXPLICITLYBYADDINGTHECOMPILEROPTIONFULLTEMPLATETYPECHECKINTHEANGULARCOMPILEROPTIONSOFTHEPROJECTSTSCONFIGJSONSEEANGULARCOMPILEROPTIONS#COMPILEROPTIONS", + "original": "In the validation phase, the Angular template compiler uses the TypeScript compiler to validate the\n binding expressions in templates. Enable this phase explicitly by adding the compiler\n option `\"fullTemplateTypeCheck\"` in the `\"angularCompilerOptions\"` of the project's `tsconfig.json` (see\n [Angular Compiler Options](#compiler-options)).", "translation": "在验证阶段,Angular 的模板编译器会使用 TypeScript 编译器来验证模板中的绑定表达式。\n 通过在项目的 `tsconfig.json`(参见 [Angular Compiler Options](#compiler-options))的 `\"angularCompilerOptions\"` 中添加编译选项 `\"fullTemplateTypeCheck\"` 可以启用这个阶段。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, @@ -2820,8 +2820,8 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, { - "key": "THEFILENAMEREPORTEDINTHEERRORMESSAGEMYCOMPONENTTSMYCOMPONENTHTMLISASYNTHETICFILEGENERATEDBYTHETEMPLATECOMPILERTHATHOLDSCONTENTSOFTHEMYCOMPONENTCLASSTEMPLATECOMPILERNEVERWRITESTHISFILETODISKTHELINEANDCOLUMNNUMBERSARERELATIVETOTHETEMPLATESTRINGINTHECOMPONENTANNOTATIONOFTHECLASSMYCOMPONENTINTHISCASEIFACOMPONENTUSESTEMPLATEURLINSTEADOFTEMPLATETHEERRORSAREREPORTEDINTHEHTMLFILEREFERENECEDBYTHETEMPLATEURLINSTEADOFASYNTHETICFILE", - "original": "The file name reported in the error message, `my.component.ts.MyComponent.html`, is a synthetic file\n generated by the template compiler that holds contents of the `MyComponent` class template.\n Compiler never writes this file to disk. The line and column numbers are relative to the template string\n in the `@Component` annotation of the class, `MyComponent` in this case. If a component uses\n `templateUrl` instead of `template`, the errors are reported in the HTML file refereneced by the\n `templateUrl` instead of a synthetic file.", + "key": "THEFILENAMEREPORTEDINTHEERRORMESSAGEMYCOMPONENTTSMYCOMPONENTHTMLISASYNTHETICFILEGENERATEDBYTHETEMPLATECOMPILERTHATHOLDSCONTENTSOFTHEMYCOMPONENTCLASSTEMPLATECOMPILERNEVERWRITESTHISFILETODISKTHELINEANDCOLUMNNUMBERSARERELATIVETOTHETEMPLATESTRINGINTHECOMPONENTANNOTATIONOFTHECLASSMYCOMPONENTINTHISCASEIFACOMPONENTUSESTEMPLATEURLINSTEADOFTEMPLATETHEERRORSAREREPORTEDINTHEHTMLFILEREFERENCEDBYTHETEMPLATEURLINSTEADOFASYNTHETICFILE", + "original": "The file name reported in the error message, `my.component.ts.MyComponent.html`, is a synthetic file\n generated by the template compiler that holds contents of the `MyComponent` class template.\n Compiler never writes this file to disk. The line and column numbers are relative to the template string\n in the `@Component` annotation of the class, `MyComponent` in this case. If a component uses\n `templateUrl` instead of `template`, the errors are reported in the HTML file referenced by the\n `templateUrl` instead of a synthetic file.", "translation": "错误信息中汇报的文件名 `my.component.ts.MyComponent.html` 是一个由模板编译器生成出的虚拟文件,\n 用于保存 `MyComponent` 类的模板内容。\n 编译器永远不会把这个文件写入磁盘。这个例子中,这里的行号和列号都是相对于 `MyComponent` 的 `@Component` 注解中的模板字符串的。\n 如果组件使用 `templateUrl` 来代替 `template`,这些错误就会在 `templateUrl` 引用的 HTML 文件中汇报,而不是这个虚拟文件中。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md" }, @@ -3054,8 +3054,8 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture-components.md" }, { - "key": "THECOMPONENTDECORATORIDENTIFIESTHECLASSIMMEDIATELYBELOWITASACOMPONENTCLASSANDSPECIFIESITSMETADATAINTHEEXAMPLECODEBELOWYOUCANSEETHATHEROLISTCOMPONENTISJUSTACLASSWITHNOSPECIALANGULARNOTATIONORSYNTAXATALLITSNOTACOMPONENTUNTILMARKITASONEWITHTHECOMPONENTDECORATOR", - "original": "The `@Component` decorator identifies the class immediately below it as a component class, and specifies its metadata. In the example code below, you can see that `HeroListComponent` is just a class, with no special Angular notation or syntax at all. It's not a component until mark it as one with the `@Component` decorator.", + "key": "THECOMPONENTDECORATORIDENTIFIESTHECLASSIMMEDIATELYBELOWITASACOMPONENTCLASSANDSPECIFIESITSMETADATAINTHEEXAMPLECODEBELOWYOUCANSEETHATHEROLISTCOMPONENTISJUSTACLASSWITHNOSPECIALANGULARNOTATIONORSYNTAXATALLITSNOTACOMPONENTUNTILYOUMARKITASONEWITHTHECOMPONENTDECORATOR", + "original": "The `@Component` decorator identifies the class immediately below it as a component class, and specifies its metadata. In the example code below, you can see that `HeroListComponent` is just a class, with no special Angular notation or syntax at all. It's not a component until you mark it as one with the `@Component` decorator.", "translation": "`@Component` 装饰器会指出紧随其后的那个类是个组件类,并为其指定元数据。\n在下面的范例代码中,你可以看到 `HeroListComponent` 只是一个普通类,完全没有 Angular 特有的标记或语法。\n直到给它加上了 `@Component` 装饰器,它才变成了组件。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture-components.md" }, @@ -5052,9 +5052,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md" }, { - "key": "FORMOREONNGMODULESYOURELIKELYTOSEEFREQUENTLYINAPPSSEEFREQUENTLYUSEDMODULES#", - "original": "For more on NgModules you're likely to see frequently in apps,\nsee [Frequently Used Modules](#).", - "translation": "要进一步了解常见的 NgModules 知识,参见 [关于模块的常见问题](#)。", + "key": "FORMOREONNGMODULESYOURELIKELYTOSEEFREQUENTLYINAPPSSEEFREQUENTLYUSEDMODULESGUIDEFREQUENTNGMODULES", + "original": "For more on NgModules you're likely to see frequently in apps,\nsee [Frequently Used Modules](guide/frequent-ngmodules).", + "translation": "要进一步了解常见的 NgModules 知识,参见 [关于模块的常见问题](guide/frequent-ngmodules)。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md" }, { @@ -6270,15 +6270,15 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/cheatsheet.md" }, { - "key": "PCALLEDAFTERCODENGAFTERCONTENTINITCODEWHENTHECOMPONENTSVIEWHASBEENINITIALIZEDAPPLIESTOCOMPONENTSONLYP", - "original": "
Called after ngAfterContentInit
when the component's view has been initialized. Applies to components only.
当ngAfterContentInit
完毕,并且组件的视图已经初始化完毕时调用。只适用于组件。
Called after ngAfterContentInit
when the component's views and child views / the view that a directive is in has been initialized.
当ngAfterContentInit
完毕,并且组件的视图及其子视图或指令所属的视图已经初始化完毕时调用。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/cheatsheet.md"
},
{
- "key": "PCALLEDAFTEREVERYCHECKOFTHECOMPONENTSVIEWAPPLIESTOCOMPONENTSONLYP",
- "original": "
Called after every check of the component's view. Applies to components only.
", - "translation": "当组件视图每次执行变更检测时调用。只适用于组件。
", + "key": "PCALLEDAFTEREVERYCHECKOFTHECOMPONENTSVIEWSANDCHILDVIEWSTHEVIEWTHATADIRECTIVEISINP", + "original": "Called after every check of the component's views and child views / the view that a directive is in.
", + "translation": "当组件的视图及其子视图或指令所属的视图每次执行变更检测时调用。
", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/cheatsheet.md" }, { @@ -7530,9 +7530,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md" }, { - "key": "WHENBUILDINGWITHTHECLIYOUMUSTCONFIGURETHEANGULARCLIJSONTOINCLUDEALLEXTERNALASSETSINCLUDINGEXTERNALSTYLEFILES", - "original": "When building with the CLI, you must configure the `.angular-cli.json` to include _all external assets_, including external style files.", - "translation": "当使用 CLI 进行构建时,你必须配置 `.angular-cli.json` 文件,使其包含*所有外部资源*(包括外部的样式表文件)。", + "key": "WHENBUILDINGWITHTHECLIYOUMUSTCONFIGURETHEANGULARJSONTOINCLUDEALLEXTERNALASSETSINCLUDINGEXTERNALSTYLEFILES", + "original": "When building with the CLI, you must configure the `angular.json` to include _all external assets_, including external style files.", + "translation": "当使用 CLI 进行构建时,你必须配置 `angular.json` 文件,使其包含*所有外部资源*(包括外部的样式表文件)。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md" }, { @@ -7704,21 +7704,21 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { - "key": "REGISTERPROVIDERSFORDEPENDENCIESUSEDTHROUGHOUTTHEAPPLICATIONINTHEROOTAPPLICATIONCOMPONENTAPPCOMPONENT", - "original": "Register providers for dependencies used throughout the application in the root application component, `AppComponent`.", - "translation": "在应用程序根组件 `AppComponent` 中注册那些被应用程序全局使用的依赖提供商。", + "key": "REGISTERPROVIDERSFORDEPENDENCIESUSEDTHROUGHOUTTHEAPPLICATIONINTHEINJECTABLEDECORATOROFTHESERVICEITSELF", + "original": "Register providers for dependencies used throughout the application \nin the `@Injectable()` decorator of the service itself.", + "translation": "在服务本身的 `@Injectable()` 装饰器中注册那些将被应用程序全局使用的依赖提供商。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { - "key": "THEFOLLOWINGEXAMPLESHOWSIMPORTINGANDREGISTERINGTHELOGGERSERVICEUSERCONTEXTANDTHEUSERSERVICEINTHECOMPONENTMETADATAPROVIDERSARRAY", - "original": "The following example shows importing and registering\nthe `LoggerService`, `UserContext`, and the `UserService`\nin the `@Component` metadata `providers` array.", - "translation": "在下面的例子中,通过 `@Component` 元数据的 `providers` 数组导入和注册了几个服务(`LoggerService`, `UserContext` 和 `UserService`)。", + "key": "PROVIDEDINHERETELLSANGULARTHATTHEROOTINJECTORISRESPONSIBLEFORCREATINGANINSTANCEOFTHEHEROSERVICESERVICESTHATAREPROVIDEDTHISWAYAREAUTOMATICALLYMADEAVAILABLETOTHEENTIREAPPLICATIONANDDONTNEEDTOBELISTEDINANYMODULE", + "original": "`providedIn` here tells Angular that the root injector is responsible for creating an instance of the `HeroService`.\nServices that are provided this way are automatically made available to the entire \napplication and don't need to be listed in any module.", + "translation": "这里的 `providedIn` 告诉 Angular,要由根注入器负责创建 `HeroService` 的实例。\n所有用这种方式提供的服务,都会自动在整个应用中可用,而不必把它们显式列在任何模块中。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { - "key": "ALLOFTHESESERVICESAREIMPLEMENTEDASCLASSESSERVICECLASSESCANACTASTHEIROWNPROVIDERSWHICHISWHYLISTINGTHEMINTHEPROVIDERSARRAYISALLTHEREGISTRATIONYOUNEED", - "original": "All of these services are implemented as classes.\nService classes can act as their own providers which is why listing them in the `providers` array\nis all the registration you need.", - "translation": "所有这些服务都是用类实现的。服务类能充当自己的提供商,这就是为什么只要把它们列在 `providers` 数组里就算注册成功了。", + "key": "SERVICECLASSESCANACTASTHEIROWNPROVIDERSWHICHISWHYDEFININGTHEMINTHEINJECTABLEDECORATORISALLTHEREGISTRATIONYOUNEED", + "original": "Service classes can act as their own providers which is why defining them in the `@Injectable` decorator\nis all the registration you need.", + "translation": "这些服务类可以充当自己的提供商,因此你只要把它们定义在 `@Injectable` 装饰器中就算注册成功了。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { @@ -7740,21 +7740,21 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { - "key": "GENERALLYREGISTERPROVIDERSINTHENGMODULERATHERTHANINTHEROOTAPPLICATIONCOMPONENT", - "original": "Generally, register providers in the `NgModule` rather than in the root application component.", - "translation": "通常会在 `NgModule` 中注册提供商,而不是在应用程序根组件中。", + "key": "IFAPROVIDERCANNOTBECONFIGUREDINTHEINJECTABLEDECORATOROFTHESERVICETHENREGISTERAPPLICATIONWIDEPROVIDERSINTHEROOTAPPMODULENOTINTHEAPPCOMPONENTGENERALLYREGISTERPROVIDERSINTHENGMODULERATHERTHANINTHEROOTAPPLICATIONCOMPONENT", + "original": "If a provider cannot be configured in the `@Injectable` decorator of the service, then register application-wide providers in the root `AppModule`, not in the `AppComponent`. Generally, register providers in the `NgModule` rather than in the root application component.", + "translation": "如果某个提供商不是在服务的 `@Injectable` 装饰器中配置的,那么就要在根模块 `AppModule` 中把它注册为全应用级的提供商,而不是在 `AppComponent` 中。\n一般来说,要在 `NgModule` 中注册提供商,而不是在应用程序根组件中。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { - "key": "DOTHISWHENYOUEXPECTTHESERVICETOBEINJECTABLEEVERYWHEREORYOUARECONFIGURINGANOTHERAPPLICATIONGLOBALSERVICEBEFORETHEAPPLICATIONSTARTS", - "original": "Do this when you expect the service to be injectable everywhere,\nor you are configuring another application global service _before the application starts_.", - "translation": "如果你希望这个服务在应用中到处都可以被注入,或者必须在应用**启动前**注册一个全局服务,那就这么做。", + "key": "DOTHISWHENUSERSSHOULDEXPLICITLYOPTINTOUSEASERVICEORTHESERVICESHOULDBEPROVIDEDINALAZILYLOADEDCONTEXTORWHENYOUARECONFIGURINGANOTHERAPPLICATIONGLOBALSERVICEBEFORETHEAPPLICATIONSTARTS", + "original": "Do this when users should explicitly opt-in to use a service, or the service should be \nprovided in a lazily-loaded context, \nor when you are configuring another application global service _before the application starts_.", + "translation": "下列情况下会用到这种方法:1. 当用户应该明确选择所用的服务时。2. 当你要在惰性加载的上下文中提供该服务时。3. 当你要在应用启动之前配置应用中的另一个全局服务时。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { - "key": "HEREISANEXAMPLEOFTHESECONDCASEWHERETHECOMPONENTROUTERCONFIGURATIONINCLUDESANONDEFAULTLOCATIONSTRATEGYGUIDEROUTER#LOCATIONSTRATEGYBYLISTINGITSPROVIDERINTHEPROVIDERSLISTOFTHEAPPMODULE", - "original": "Here is an example of the second case, where the component router configuration includes a non-default\n[location strategy](guide/router#location-strategy) by listing its provider\nin the `providers` list of the `AppModule`.", - "translation": "下面的例子是第二种情况,它为组件路由器配置了一个非默认的[地址策略(location strategy)](guide/router#location-strategy),并把它加入到 `AppModule` 的 `providers` 数组中。", + "key": "HEREISANEXAMPLEOFTHECASEWHERETHECOMPONENTROUTERCONFIGURATIONINCLUDESANONDEFAULTLOCATIONSTRATEGYGUIDEROUTER#LOCATIONSTRATEGYBYLISTINGITSPROVIDERINTHEPROVIDERSLISTOFTHEAPPMODULE", + "original": "Here is an example of the case where the component router configuration includes a non-default\n[location strategy](guide/router#location-strategy) by listing its provider\nin the `providers` list of the `AppModule`.", + "translation": "下面的例子就属于这些情况,它为组件路由器配置了一个非默认的[地址策略(location strategy)](guide/router#location-strategy),并把它加入到 `AppModule` 的 `providers` 数组中。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { @@ -7818,33 +7818,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { - "key": "THATDECORATORMAKESITPOSSIBLEFORANGULARTOIDENTIFYTHETYPESOFITSTWODEPENDENCIESLOGGERSERVICEANDUSERSERVICE", - "original": "That decorator makes it possible for Angular to identify the types of its two dependencies, `LoggerService` and `UserService`.", - "translation": "该装饰器让 Angular 有能力识别这两个依赖 `LoggerService` 和 `UserService` 的类型。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" - }, - { - "key": "TECHNICALLYTHEINJECTABLEDECORATORISONLYREQUIREDFORASERVICECLASSTHATHASITSOWNDEPENDENCIESTHELOGGERSERVICEDOESNTDEPENDONANYTHINGTHELOGGERWOULDWORKIFYOUOMITTEDINJECTABLEANDTHEGENERATEDCODEWOULDBESLIGHTLYSMALLER", - "original": "Technically, the `@Injectable()`decorator is only required for a service class that has _its own dependencies_.\nThe `LoggerService` doesn't depend on anything. The logger would work if you omitted `@Injectable()`\nand the generated code would be slightly smaller.", - "translation": "严格来说,这个 `@Injectable()` 装饰器只在一个服务类有*自己的依赖*的时候,才是*不可缺少*的。\n`LoggerService` 不依赖任何东西,所以该日志服务在没有 `@Injectable()` 的时候应该也能工作,生成的代码也更少一些。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" - }, - { - "key": "BUTTHESERVICEWOULDBREAKTHEMOMENTYOUGAVEITADEPENDENCYANDYOUDHAVETOGOBACKANDADDINJECTABLETOFIXITADDINJECTABLEFROMTHESTARTFORTHESAKEOFCONSISTENCYANDTOAVOIDFUTUREPAIN", - "original": "But the service would break the moment you gave it a dependency and you'd have to go back\nand add `@Injectable()` to fix it. Add `@Injectable()` from the start for the sake\nof consistency and to avoid future pain.", - "translation": "但是在给它添加依赖的那一瞬间,该服务就会停止工作,要想修复它,就必须要添加 `@Injectable()`。\n为了保持一致性和防止将来的麻烦,推荐从一开始就加上 `@Injectable()`。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" - }, - { - "key": "ALTHOUGHTHISSITERECOMMENDSAPPLYINGINJECTABLETOALLSERVICECLASSESDONTFEELBOUNDBYITSOMEDEVELOPERSPREFERTOADDITONLYWHERENEEDEDANDTHATSAREASONABLEPOLICYTOO", - "original": "Although this site recommends applying `@Injectable()` to all service classes, don't feel bound by it.\nSome developers prefer to add it only where needed and that's a reasonable policy too.", - "translation": "虽然推荐在所有服务中使用 `@Injectable()`,但你也不需要一定要这么做。一些开发者就更喜欢在真正需要的地方才添加,这也是一个合理的策略。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" - }, - { - "key": "THEAPPCOMPONENTCLASSHADTWODEPENDENCIESASWELLBUTNOINJECTABLEITDIDNTNEEDINJECTABLEBECAUSETHATCOMPONENTCLASSHASTHECOMPONENTDECORATORINANGULARWITHTYPESCRIPTASINGLEDECORATORMDASHANYDECORATORMDASHISSUFFICIENTTOIDENTIFYDEPENDENCYTYPES", - "original": "The `AppComponent` class had two dependencies as well but no `@Injectable()`.\nIt didn't need `@Injectable()` because that component class has the `@Component` decorator.\nIn Angular with TypeScript, a *single* decorator—*any* decorator—is sufficient to identify dependency types.", - "translation": "`AppComponent` 类有两个依赖,但它没有 `@Injectable()`。\n它不需要 `@Injectable()`,这是因为组件类有 `@Component` 装饰器。\n在用 TypeScript 的 Angular 应用里,有一个*单独的*装饰器 — *任何*装饰器 — 来标识依赖的类型就够了。", + "key": "THEINJECTABLEDECORATORINDICATESTHATTHEANGULARDISYSTEMISUSEDTOCREATEONEORMOREINSTANCESOFUSERCONTEXTSERVICE", + "original": "The `@Injectable` decorator indicates that the Angular DI system is used to create one or more instances of `UserContextService`.", + "translation": "`@Injectable` 装饰器会向 Angular DI 系统指明应该为 `UserContextService` 创建一个实例还是多个实例。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { @@ -8178,9 +8154,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { - "key": "ANEWINJECTORHASNOPROVIDERSANGULARINITIALIZESTHEINJECTORSITCREATESWITHSOMEPROVIDERSITCARESABOUTYOUHAVETOREGISTERYOUROWNAPPLICATIONPROVIDERSMANUALLYUSUALLYINTHEPROVIDERSARRAYOFTHECOMPONENTORDIRECTIVEMETADATA:", - "original": "A new injector has no providers.\nAngular initializes the injectors it creates with some providers it cares about.\nYou have to register your _own_ application providers manually,\nusually in the `providers` array of the `Component` or `Directive` metadata:", - "translation": "新建的注入器中没有提供商。\nAngular 会使用一些自带的提供商来初始化这些注入器。你必须自行注册属于*自己*的提供商,通常用 ` 组件 ` 或者 ` 指令 ` 元数据中的 `providers` 数组进行注册。", + "key": "ANEWINJECTORHASNOPROVIDERSANGULARINITIALIZESTHEINJECTORSITCREATESWITHSOMEPROVIDERSITCARESABOUTYOUHAVETOREGISTERYOUROWNAPPLICATIONPROVIDERSMANUALLYUSUALLYINTHEINJECTABLEDECORATOROFTHESERVICEPROVIDERSARRAYOFTHENGMODULEORDIRECTIVEMETADATA:", + "original": "A new injector has no providers.\nAngular initializes the injectors it creates with some providers it cares about.\nYou have to register your _own_ application providers manually,\nusually in the `@Injectable` decorator of the service, `providers` array of the `NgModule` or `Directive` metadata:", + "translation": "新建的注入器中没有提供商。\nAngular 会使用一些自带的提供商来初始化这些注入器。你必须自行注册属于*自己*的提供商,通常会在该服务的 `@Injectable` 装饰器中,或在 `NgModule` 或 `Directive` 元数据的 `providers` 数组中进行注册。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { @@ -8190,9 +8166,15 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { - "key": "THESIMPLECLASSPROVIDERISTHEMOSTTYPICALBYFARYOUMENTIONTHECLASSINTHEPROVIDERSARRAYANDYOUREDONE", - "original": "The simple class provider is the most typical by far.\nYou mention the class in the `providers` array and you're done.", - "translation": "简单的类提供商是最典型的例子。只要在 `providers` 数值里面提到该类就可以了。", + "key": "THESIMPLEWAYOFDEFININGPROVIDERSINTHEINJECTABLEDECORATOROFTHECLASSISRECOMMENDED", + "original": "The simple way of defining providers in the `@Injectable` decorator of the class is recommended.", + "translation": "建议直接在服务类的 `@Injectable` 装饰器中定义服务提供商。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" + }, + { + "key": "ANOTHERALTERNATIVEISTOMENTIONTHECLASSINTHEPROVIDERSARRAYOFTHENGMODULEANDYOUREDONE", + "original": "Another alternative is to mention the class in the providers array of the `@NgModule` and you're done.", + "translation": "备选方案是在 `@NgModule` 的 `providers` 数组中引用下这个类就可以了。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection-in-action.md" }, { @@ -9282,15 +9264,15 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "THATCOMMANDCREATESTHEFOLLOWINGHEROSERVICESKELETON", - "original": "That command creates the following `HeroService` skeleton.", - "translation": "这条命令会创建如下的 `HeroService` 骨架代码:", + "key": "THECOMMANDABOVECREATESTHEFOLLOWINGHEROSERVICESKELETON", + "original": "The command above creates the following `HeroService` skeleton.", + "translation": "上述命令会创建如下的 `HeroService` 骨架代码:", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "ASSUMEFORNOWTHATTHEINJECTABLEDECORATOR#INJECTABLEISANESSENTIALINGREDIENTINEVERYANGULARSERVICEDEFINITIONTHERESTOFTHECLASSHASBEENREWRITTENTOEXPOSEAGETHEROESMETHODTHATRETURNSTHESAMEMOCKDATAASBEFORE", - "original": "Assume for now that the [`@Injectable` decorator](#injectable) is an essential ingredient in every Angular service definition.\nThe rest of the class has been rewritten to expose a `getHeroes` method \nthat returns the same mock data as before.", - "translation": "目前先把 [`@Injectable` 装饰器](#injectable)当做定义每个 Angular 服务时的必备部分。\n把该类的其它部分改写为暴露一个返回和以前一样的 mock 数据的 `getHeroes` 方法。", + "key": "THEINJECTABLEDECORATORISANESSENTIALINGREDIENTINEVERYANGULARSERVICEDEFINITIONTHERESTOFTHECLASSHASBEENREWRITTENTOEXPOSEAGETHEROESMETHODTHATRETURNSTHESAMEMOCKDATAASBEFORE", + "original": "The `@Injectable` decorator is an essential ingredient in every Angular service definition.\nThe rest of the class has been rewritten to expose a `getHeroes` method \nthat returns the same mock data as before.", + "translation": "[`@Injectable` 装饰器](#injectable)是定义每个 Angular 服务时的必备部分。\n把该类的其它部分改写为暴露一个返回和以前一样的 mock 数据的 `getHeroes` 方法。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { @@ -9306,15 +9288,15 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "##REGISTERASERVICEPROVIDER", - "original": "## Register a service provider", - "translation": "## 注册服务提供商", + "key": "##INJECTORS", + "original": "## Injectors", + "translation": "## 注入器", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "ASERVICEISJUSTACLASSINANGULARUNTILYOUREGISTERITWITHANANGULARDEPENDENCYINJECTOR", - "original": "A _service_ is just a class in Angular until you register it with an Angular dependency injector.", - "translation": "在你把 Angular 中的*服务*注册进依赖注入器(injector)之前,它只是一个普通的类。", + "key": "ASERVICELIKEHEROSERVICEISJUSTACLASSINANGULARUNTILYOUREGISTERITWITHANANGULARDEPENDENCYINJECTOR", + "original": "A _service_ like `HeroService` is just a class in Angular until you register it with an Angular dependency injector.", + "translation": "在你把 Angular 中的*服务类*(比如 `HeroService` )注册进依赖注入器(injector)之前,它只是个普通类而已。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { @@ -9330,9 +9312,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "YOUDOHAVETOREGISTERPROVIDERSWITHANINJECTORBEFORETHEINJECTORCANCREATETHATSERVICE", - "original": "You do have to register _providers_ with an injector \nbefore the injector can create that service.", - "translation": "但在注入器能创建服务之前,你得先往注入器中注入这个服务的*提供商*。", + "key": "ANGULARDOESNTAUTOMATICALLYKNOWHOWYOUWANTTOCREATEINSTANCESOFYOURSERVICESORTHEINJECTORTOCREATEYOURSERVICEYOUMUSTCONFIGUREITBYSPECIFYINGPROVIDERSFOREVERYSERVICE", + "original": "Angular doesn't automatically know how you want to create instances of your services or the injector to create your service. You must configure it by specifying providers for every service.", + "translation": "Angular 本身没法自动判断你是打算自行创建服务类的实例,还是等注入器来创建它。你必须通过为每个服务指定服务提供商来配置它。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { @@ -9342,33 +9324,51 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "YOULLLEARNMUCHMOREABOUTPROVIDERSBELOW#PROVIDERSFORNOWITISSUFFICIENTTOKNOWTHATTHEYCREATESERVICESANDMUSTBEREGISTEREDWITHANINJECTOR", - "original": "You'll learn much more about _providers_ [below](#providers).\nFor now it is sufficient to know that they create services\nand must be registered with an injector.", - "translation": "你可以在[稍后的部分](#providers)学到更多关于*提供商*的知识。\n不过目前,只要知道它们用于创建服务,以及它们必须用注入器进行注册就行了。", + "key": "YOULLLEARNMUCHMOREABOUTPROVIDERSBELOW#PROVIDERSFORNOWITISSUFFICIENTTOKNOWTHATTHEYCONFIGUREWHEREANDHOWSERVICESARECREATED", + "original": "You'll learn much more about _providers_ [below](#providers).\nFor now, it is sufficient to know that they configure where and how services are created.", + "translation": "你可以在[稍后的部分](#providers)学到更多关于*提供商*的知识。\n不过目前,你只要知道它们是用来配置服务应该在哪里创建以及如何创建的就够了。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "YOUCANREGISTERAPROVIDERWITHANYANGULARDECORATORTHATSUPPORTSTHEPROVIDERSARRAYPROPERTY", - "original": "You can register a provider with any Angular decorator that supports the **`providers` array property**.", - "translation": "你可以使用 Angular 中那些支持 `providers` 数组属性的装饰器来注册提供商。", + "key": "THEREAREMANYWAYSTOREGISTERASERVICEPROVIDERWITHANINJECTORTHISSECTIONSHOWSTHEMOSTCOMMONWAYSOFCONFIGURINGAPROVIDERFORYOURSERVICES", + "original": "There are many ways to register a service provider with an injector. This section shows the most common ways \nof configuring a provider for your services.", + "translation": "有很多方式可以为注入器注册服务提供商。本节会展示为你的服务配置提供商最常见的途径。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "MANYANGULARDECORATORSACCEPTMETADATAWITHAPROVIDERSPROPERTYTHETWOMOSTIMPORTANTEXAMPLESARECOMPONENTANDNGMODULE", - "original": "Many Angular decorators accept metadata with a `providers` property.\nThe two most important examples are `@Component` and `@NgModule`.", - "translation": "很多 Angular 的装饰器都支持带有 `providers` 属性的元数据。\n最重要的两个例子是 `@Component` 和 `@NgModule`。", + "key": "##INJECTABLEPROVIDERS", + "original": "## @Injectable providers", + "translation": "## @Injectable 的 providers 数组", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "###COMPONENTPROVIDERS", - "original": "### _@Component_ providers", - "translation": "### 在组件中注册提供商", + "key": "THEINJECTABLEDECORATORIDENTIFIESSERVICESANDOTHERCLASSESTHATAREINTENDEDTOBEINJECTEDITCANALSOBEUSEDTOCONFIGUREAPROVIDERFORTHOSESERVICES", + "original": "The `@Injectable` decorator identifies services and other classes that are intended to be injected. It can also be used to configure a provider for those services.", + "translation": "`@Injectable` 装饰器会指出这些服务或其它类是用来注入的。它还能用于为这些服务提供配置项。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "HERESAREVISEDHEROESCOMPONENTTHATREGISTERSTHEHEROSERVICEINITSPROVIDERSARRAY", - "original": "Here's a revised `HeroesComponent` that registers the `HeroService` in its `providers` array.", - "translation": "下面是修改过的 `HerosComponent`,把 `HeroService` 注册到了它的 `providers` 数组中。", + "key": "HEREWECONFIGUREAPROVIDERFORHEROSERVICEUSINGTHEINJECTABLEDECORATORONTHECLASS", + "original": "Here we configure a provider for `HeroService` using the `@Injectable` decorator on the class.", + "translation": "这里我们使用类上的 `@Injectable` 装饰器来为 `HeroService` 配置了一个提供商。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "PROVIDEDINTELLSANGULARTHATTHEROOTINJECTORISRESPONSIBLEFORCREATINGANINSTANCEOFTHEHEROSERVICEBYINVOKINGITSCONSTRUCTORANDMAKINGITAVAILABLEACROSSTHEAPPLICATIONTHECLISETSUPTHISKINDOFAPROVIDERAUTOMATICALLYFORYOUWHENGENERATINGANEWSERVICE", + "original": "`providedIn` tells Angular that the root injector is responsible for creating an instance of the `HeroService` (by invoking its constructor) and making it available across the application. The CLI sets up this kind of a provider automatically for you when generating a new service.", + "translation": "`providedIn` 告诉 Angular,它的根注入器要负责调用 `HeroService` 类的构造函数来创建一个实例,并让它在整个应用中都是可用的。在使用 CLI 生成新服务时,会默认帮你设置为这种提供商。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "SOMETIMESITSNOTDESIRABLETOHAVEASERVICEALWAYSBEPROVIDEDINTHEAPPLICATIONROOTINJECTORPERHAPSUSERSSHOULDEXPLICITLYOPTINTOUSINGTHESERVICEORTHESERVICESHOULDBEPROVIDEDINALAZILYLOADEDCONTEXTINTHISCASETHEPROVIDERSHOULDBEASSOCIATEDWITHASPECIFICNGMODULECLASSANDWILLBEUSEDBYWHICHEVERINJECTORINCLUDESTHATMODULE", + "original": "Sometimes it's not desirable to have a service always be provided in the application root injector. Perhaps users should explicitly opt-in to using the service, or the service should be provided in a lazily-loaded context. In this case, the provider should be associated with a specific `@NgModule` class, and will be used by whichever injector includes that module.", + "translation": "有时,你不希望只在应用的根注入器中提供服务。有可能用户希望显式选择要使用的服务,或者应该在一个惰性加载的环境下提供该服务。这种情况下,服务提供商应该关联到一个特定的 `@NgModule` 类,而且应该用于该模块包含的任何一个注入器中。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "INTHEFOLLOWINGEXCERPTTHEINJECTABLEDECORATORISUSEDTOCONFIGUREAPROVIDERTHATWILLBEAVAILABLEINANYINJECTORTHATINCLUDESTHEHEROMODULE", + "original": "In the following excerpt, the `@Injectable` decorator is used to configure a provider that will be available in any injector that includes the HeroModule.", + "translation": "下面这段代码中,`@Injectable` 装饰器用来配置一个服务提供商,它可以用在任何包含了 HeroModule 的注入器中。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { @@ -9390,9 +9390,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "THANKSTOTHESEREGISTRATIONSANGULARCANINJECTTHEUSERSERVICEORTHEHERODICONFIGVALUEINTOANYCLASSTHATITCREATES", - "original": "Thanks to these registrations, Angular can inject the `UserService` or the `HERO_DI_CONFIG` value\ninto any class that it creates.", - "translation": "得益于这些注册语句,Angular 现在可以向它创建的任何类中注册 `UserService` 或 `HERO_DI_CONFIG` 值了。", + "key": "WITHTHEABOVEREGISTRATIONSANGULARCANINJECTTHEUSERSERVICEORTHEHERODICONFIGVALUEINTOANYCLASSTHATITCREATES", + "original": "With the above registrations, Angular can inject the `UserService` or the `HERO_DI_CONFIG` value\ninto any class that it creates.", + "translation": "借助这些注册语句,Angular 现在可以向它创建的任何类中注册 `UserService` 或 `HERO_DI_CONFIG` 值了。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { @@ -9402,15 +9402,39 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "###NGMODULEORCOMPONENT", - "original": "### _@NgModule_ or _@Component_?", - "translation": "### _@NgModule_ 还是 _@Component_?", + "key": "###COMPONENTPROVIDERS", + "original": "### _@Component_ providers", + "translation": "### 在组件中注册提供商", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "SHOULDYOUREGISTERASERVICEWITHANANGULARMODULEORWITHACOMPONENTTHETWOCHOICESLEADTODIFFERENCESINSERVICESCOPEANDSERVICELIFETIME", - "original": "Should you register a service with an Angular module or with a component?\nThe two choices lead to differences in service _scope_ and service _lifetime_.", - "translation": "你该使用 Angular 的模块还是组件来注册服务呢?\n这两个选择的差别在于服务的*范围*和*生命周期*。", + "key": "INADDITIONTOPROVIDINGTHESERVICEAPPLICATIONWIDEORWITHINAPARTICULARNGMODULESERVICESCANALSOBEPROVIDEDINSPECIFICCOMPONENTSSERVICESPROVIDEDINCOMPONENTLEVELISONLYAVAILABLEWITHINTHATCOMPONENTINJECTORORINANYOFITSCHILDCOMPONENTS", + "original": "In addition to providing the service application-wide or within a particular `@NgModule`, services can also be provided in specific components. Services provided in component-level is only available within that component injector or in any of its child components.", + "translation": "除了提供给全应用级或特定的 `@NgModule` 中之外,服务还可以提供给指定的组件。在组件级提供的服务职能在该组件及其子组件的注入器中使用。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "THEEXAMPLEBELOWSHOWSAREVISEDHEROESCOMPONENTTHATREGISTERSTHEHEROSERVICEINITSPROVIDERSARRAY", + "original": "The example below shows a revised `HeroesComponent` that registers the `HeroService` in its `providers` array.", + "translation": "下面的例子展示了一个修改过的 `HeroesComponent`,它在自己的 `providers` 数组中注册了 `HeroService`。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "###INJECTABLENGMODULEORCOMPONENT", + "original": "### @Injectable, _@NgModule_ or _@Component_?", + "translation": "### @Injectable、_@NgModule_ 还是 _@Component_ ?", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "SHOULDYOUPROVIDEASERVICEWITHANINJECTABLEDECORATORINANNGMODULEORWITHINANCOMPONENTTHECHOICESLEADTODIFFERENCESINTHEFINALBUNDLESIZESERVICESCOPEANDSERVICELIFETIME", + "original": "Should you provide a service with an `@Injectable` decorator, in an `@NgModule`, or within an `@Component`?\nThe choices lead to differences in the final bundle size, service _scope_, and service _lifetime_.", + "translation": "你该使用 `@Injectable` 装饰器、`@NgModule`还是 `@Component` 来提供服务呢?\n这几个选择的差别在于最终的打包体积、服务的*范围*和服务的*生命周期*。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "WHENYOUREGISTERPROVIDERSINTHEINJECTABLEDECORATOROFTHESERVICEITSELFOPTIMIZATIONTOOLSSUCHASTHOSEUSEDBYTHECLISPRODUCTIONBUILDSCANPERFORMTREESHAKINGWHICHREMOVESSERVICESTHATARENTUSEDBYYOURAPPTREESHAKINGRESULTSINSMALLERBUNDLESIZES", + "original": "When you register providers in the **@Injectable** decorator of the service itself, optimization tools such as those used by the CLI's production builds can perform tree shaking, which removes services that aren't used by your app. Tree shaking results in smaller bundle sizes.", + "translation": "当你在服务本身的 **@Injectable** 装饰器中注册提供商时,优化工具(比如 CLI 产品模式构建时所用的)可以执行摇树优化,这会移除所有没在应用中使用过的服务。摇树优化会导致更小的打包体积。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { @@ -9420,9 +9444,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "YOURELIKELYTOINJECTTHEUSERSERVICEINMANYPLACESTHROUGHOUTTHEAPPANDWILLWANTTOINJECTTHESAMESERVICEINSTANCEEVERYTIMEPROVIDINGTHEUSERSERVICEWITHANANGULARMODULEISAGOODCHOICE", - "original": "You're likely to inject the `UserService` in many places throughout the app\nand will want to inject the same service instance every time.\nProviding the `UserService` with an Angular module is a good choice.", - "translation": "如果你想要把这个 `UserService` 注入到应用中的很多地方,并且期望每次注入的都是同一个服务实例,那么在 Angular 的模块中提供 `UserService` 就是不错的选择。", + "key": "YOURELIKELYTOINJECTTHEUSERSERVICEINMANYPLACESTHROUGHOUTTHEAPPANDWILLWANTTOINJECTTHESAMESERVICEINSTANCEEVERYTIMEPROVIDINGTHEUSERSERVICEWITHANANGULARMODULEISAGOODCHOICEIFANINJECTABLEPROVIDERISNOTANOPTION", + "original": "You're likely to inject the `UserService` in many places throughout the app\nand will want to inject the same service instance every time.\nProviding the `UserService` with an Angular module is a good choice if an `@Injectable` provider is not an option.", + "translation": "你可能想要把这个 `UserService` 注入到应用中的很多地方,并期望每次注入的都是同一个服务实例。\n这时候如果不能用 `@Injectable`,那么就可以在 Angular 的模块中提供 `UserService`。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { @@ -9467,246 +9491,6 @@ "translation": "由组件提供的服务,其范围和生命周期是 [Angular 如何创建组件实例](#component-child-injectors) 的必然结果。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, - { - "key": "##INJECTASERVICE", - "original": "## Inject a service", - "translation": "## 注入某个服务", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "THEHEROLISTCOMPONENTSHOULDGETHEROESFROMTHEHEROSERVICE", - "original": "The `HeroListComponent` should get heroes from the `HeroService`.", - "translation": "`HeroListComponent` 应该从 `HeroService` 中获取这些英雄数据。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "THECOMPONENTSHOULDNTCREATETHEHEROSERVICEWITHNEWITSHOULDASKFORTHEHEROSERVICETOBEINJECTED", - "original": "The component shouldn't create the `HeroService` with `new`.\nIt should ask for the `HeroService` to be injected.", - "translation": "该组件不应该使用 `new` 来创建 `HeroService`。\n它应该要求注入 `HeroService`。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "YOUCANTELLANGULARTOINJECTADEPENDENCYINTHECOMPONENTSCONSTRUCTORBYSPECIFYINGACONSTRUCTORPARAMETERWITHTHEDEPENDENCYTYPEHERESTHEHEROLISTCOMPONENTCONSTRUCTORASKINGFORTHEHEROSERVICETOBEINJECTED", - "original": "You can tell Angular to inject a dependency in the component's constructor by specifying a **constructor parameter with the dependency type**.\nHere's the `HeroListComponent` constructor, asking for the `HeroService` to be injected.", - "translation": "你可以通过**在构造函数中添加一个带有该依赖类型的参数**来要求 Angular 把这个依赖注入到组件的构造函数中。\n下面是 `HeroListComponent` 的构造函数,它要求注入 `HeroService`。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "OFCOURSETHEHEROLISTCOMPONENTSHOULDDOSOMETHINGWITHTHEINJECTEDHEROSERVICEHERESTHEREVISEDCOMPONENTMAKINGUSEOFTHEINJECTEDSERVICESIDEBYSIDEWITHTHEPREVIOUSVERSIONFORCOMPARISON", - "original": "Of course, the `HeroListComponent` should do something with the injected `HeroService`.\nHere's the revised component, making use of the injected service, side-by-side with the previous version for comparison.", - "translation": "当然,`HeroListComponent` 还应该使用注入的这个 `HeroService` 做点什么。\n下面输出修改过的组件,改用注入的服务,与前一个版本对比一下。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "NOTICETHATTHEHEROLISTCOMPONENTDOESNTKNOWWHERETHEHEROSERVICECOMESFROMYOUKNOWTHATITCOMESFROMTHEPARENTHEROESCOMPONENTBUTIFYOUDECIDEDINSTEADTOPROVIDETHEHEROSERVICEINTHEAPPMODULETHEHEROLISTCOMPONENTWOULDNTCHANGEATALLTHEONLYTHINGTHATMATTERSISTHATTHEHEROSERVICEISPROVIDEDINSOMEPARENTINJECTOR", - "original": "Notice that the `HeroListComponent` doesn't know where the `HeroService` comes from.\n_You_ know that it comes from the parent `HeroesComponent`.\nBut if you decided instead to provide the `HeroService` in the `AppModule`,\nthe `HeroListComponent` wouldn't change at all.\nThe _only thing that matters_ is that the `HeroService` is provided in some parent injector.", - "translation": "注意,`HeroListComponent` 并不知道 `HeroService` 来自哪里。\n当然*你自己*知道它来自父组件 `HeroesComponent`。\n但是如果你决定改在 `AppModule` 中提供 `HeroService`,`HeroListComponent` 不用做任何修改。\n它*唯一需要关心的事情*是 `HeroService` 是由某个父注入器提供的。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "##SINGLETONSERVICES", - "original": "## Singleton services", - "translation": "## 单例服务", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "SERVICESARESINGLETONSWITHINTHESCOPEOFANINJECTORTHEREISATMOSTONEINSTANCEOFASERVICEINAGIVENINJECTOR", - "original": "Services are singletons _within the scope of an injector_.\nThere is at most one instance of a service in a given injector.", - "translation": "服务*在每个注入器的范围内*是单例的。\n在任何一个注入器中,最多只会有同一个服务的一个实例。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "THEREISONLYONEROOTINJECTORANDTHEUSERSERVICEISREGISTEREDWITHTHATINJECTORTHEREFORETHERECANBEJUSTONEUSERSERVICEINSTANCEINTHEENTIREAPPANDEVERYCLASSTHATINJECTSUSERSERVICEGETTHISSERVICEINSTANCE", - "original": "There is only one root injector and the `UserService` is registered with that injector.\nTherefore, there can be just one `UserService` instance in the entire app\nand every class that injects `UserService` get this service instance.", - "translation": "这里只有一个根注入器,而 `UserService` 就是在该注入器中注册的。\n所以,在整个应用中只能有一个 `UserService` 实例,每个要求注入 `UserService` 的类都会得到这个服务实例。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "HOWEVERANGULARDIISAHIERARCHICALINJECTIONSYSTEMGUIDEHIERARCHICALDEPENDENCYINJECTIONWHICHMEANSTHATNESTEDINJECTORSCANCREATETHEIROWNSERVICEINSTANCESANGULARCREATESNESTEDINJECTORSALLTHETIME", - "original": "However, Angular DI is a \n[hierarchical injection system](guide/hierarchical-dependency-injection), \nwhich means that nested injectors can create their own service instances.\nAngular creates nested injectors all the time.", - "translation": "不过,Angular DI 是一个 [多级注入系统](guide/hierarchical-dependency-injection),这意味着各级注入器都可以创建它们自己的服务实例。\nAngular 总会创建多级注入器。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "##COMPONENTCHILDINJECTORS", - "original": "## Component child injectors", - "translation": "## 组件的子注入器", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "FOREXAMPLEWHENANGULARCREATESANEWINSTANCEOFACOMPONENTTHATHASCOMPONENTPROVIDERSITALSOCREATESANEWCHILDINJECTORFORTHATINSTANCE", - "original": "For example, when Angular creates a new instance of a component that has `@Component.providers`,\nit also creates a new _child injector_ for that instance.", - "translation": "例如,当 Angular 创建一个带有 `@Component.providers` 的组件实例时,也会同时为这个实例创建一个新的*子注入器*。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "COMPONENTINJECTORSAREINDEPENDENTOFEACHOTHERANDEACHOFTHEMCREATESITSOWNINSTANCESOFTHECOMPONENTPROVIDEDSERVICES", - "original": "Component injectors are independent of each other and\neach of them creates its own instances of the component-provided services.", - "translation": "组件注入器是彼此独立的,每一个都会为这些组件提供的服务创建单独的实例。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "WHENANGULARDESTROYSONEOFTHESECOMPONENTINSTANCEITALSODESTROYSTHECOMPONENTSINJECTORANDTHATINJECTORSSERVICEINSTANCES", - "original": "When Angular destroys one of these component instance, it also destroys the\ncomponent's injector and that injector's service instances.", - "translation": "当 Angular 销毁任何一个组件实例时,也会同时销毁组件的注入器以及该注入器中的那些服务实例。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "THANKSTOINJECTORINHERITANCEGUIDEHIERARCHICALDEPENDENCYINJECTIONYOUCANSTILLINJECTAPPLICATIONWIDESERVICESINTOTHESECOMPONENTSACOMPONENTSINJECTORISACHILDOFITSPARENTCOMPONENTSINJECTORANDADESCENDENTOFITSPARENTSPARENTSINJECTORANDSOONALLTHEWAYBACKTOTHEAPPLICATIONSROOTINJECTORANGULARCANINJECTASERVICEPROVIDEDBYANYINJECTORINTHATLINEAGE", - "original": "Thanks to [injector inheritance](guide/hierarchical-dependency-injection),\nyou can still inject application-wide services into these components.\nA component's injector is a child of its parent component's injector,\nand a descendent of its parent's parent's injector, and so on all the way back to the application's _root_ injector.\nAngular can inject a service provided by any injector in that lineage.", - "translation": "在[注入器继承机制](guide/hierarchical-dependency-injection)的帮助下,你仍然可以把全应用级的服务注入到这些组件中。\n组件的注入器也是其父组件的注入器的子注入器,这同样适用于其父组件的父组件的注入器,以此类推,最终会回到应用的*根*注入器。\nAngular 可以注入由这个注入器谱系提供的任何一个注入器。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "FOREXAMPLEANGULARCOULDINJECTAHEROLISTCOMPONENTWITHBOTHTHEHEROSERVICEPROVIDEDINHEROCOMPONENTANDTHEUSERSERVICEPROVIDEDINAPPMODULE", - "original": "For example, Angular could inject a `HeroListComponent`\nwith both the `HeroService` provided in `HeroComponent`\nand the `UserService` provided in `AppModule`.", - "translation": "比如,Angular 可以把由 `HeroComponent` 提供的 `HeroService` 和由 `AppModule` 提供的 `UserService` 注入到 `HeroService` 中。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "##TESTINGTHECOMPONENT", - "original": "## Testing the component", - "translation": "## 测试组件", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "EARLIERYOUSAWTHATDESIGNINGACLASSFORDEPENDENCYINJECTIONMAKESTHECLASSEASIERTOTESTLISTINGDEPENDENCIESASCONSTRUCTORPARAMETERSMAYBEALLYOUNEEDTOTESTAPPLICATIONPARTSEFFECTIVELY", - "original": "Earlier you saw that designing a class for dependency injection makes the class easier to test.\nListing dependencies as constructor parameters may be all you need to test application parts effectively.", - "translation": "前面强调过,设计一个适合依赖注入的类,可以让这个类更容易测试。\n要有效的测试应用中的一部分,只需要在构造函数的参数中列出依赖。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "FOREXAMPLEYOUCANCREATEANEWHEROLISTCOMPONENTWITHAMOCKSERVICETHATYOUCANMANIPULATEUNDERTEST:", - "original": "For example, you can create a new `HeroListComponent` with a mock service that you can manipulate\nunder test:", - "translation": "例如,新建的 `HeroListComponent` 实例使用一个模拟 (mock) 服务,以便可以在测试中操纵它:", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "LEARNMOREINTHETESTINGGUIDETESTINGGUIDE", - "original": "Learn more in the [Testing](guide/testing) guide.", - "translation": "要学习更多知识,参见[测试](guide/testing)一章。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "##WHENTHESERVICENEEDSASERVICE", - "original": "## When the service needs a service", - "translation": "## 当服务需要别的服务时", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "THEHEROSERVICEISVERYSIMPLEITDOESNTHAVEANYDEPENDENCIESOFITSOWN", - "original": "The `HeroService` is very simple. It doesn't have any dependencies of its own.", - "translation": "这个 `HeroService` 非常简单。它本身不需要任何依赖。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "WHATIFITHADADEPENDENCYWHATIFITREPORTEDITSACTIVITIESTHROUGHALOGGINGSERVICEYOUDAPPLYTHESAMECONSTRUCTORINJECTIONPATTERNADDINGACONSTRUCTORTHATTAKESALOGGERPARAMETER", - "original": "What if it had a dependency? What if it reported its activities through a logging service?\nYou'd apply the same *constructor injection* pattern,\nadding a constructor that takes a `Logger` parameter.", - "translation": "如果它也有依赖,该怎么办呢?例如,它需要通过日志服务来汇报自己的活动。\n你同样用*构造函数注入*模式,来添加一个带有 `Logger` 参数的构造函数。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "HEREISTHEREVISEDHEROSERVICETHATINJECTSTHELOGGERSIDEBYSIDEWITHTHEPREVIOUSSERVICEFORCOMPARISON", - "original": "Here is the revised `HeroService` that injects the `Logger`, side-by-side with the previous service for comparison.", - "translation": "下面是修改后的 `HeroService`,它注入了 `Logger`,对比前后这两个版本:", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "THECONSTRUCTORASKSFORANINJECTEDINSTANCEOFALOGGERANDSTORESITINAPRIVATEFIELDCALLEDLOGGERTHEGETHEROESMETHODLOGSAMESSAGEWHENASKEDTOFETCHHEROES", - "original": "The constructor asks for an injected instance of a `Logger` and stores it in a private field called `logger`.\nThe `getHeroes()` method logs a message when asked to fetch heroes.", - "translation": "这个构造函数要求注入一个 `Logger` 类的实例,并把它存到名为 `logger` 的私有字段中。\n 当请求英雄数据时,`getHeroes()` 中就会记录一个消息。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "####THEDEPENDENTLOGGERSERVICE", - "original": "#### The dependent _Logger_ service", - "translation": "#### 被依赖的 `Logger` 服务", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "THESAMPLEAPPSLOGGERSERVICEISQUITESIMPLE:", - "original": "The sample app's `Logger` service is quite simple:", - "translation": "这个范例应用的 `Logger` 服务非常简单:", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "IFTHEAPPDIDNTPROVIDETHISLOGGERANGULARWOULDTHROWANEXCEPTIONWHENITLOOKEDFORALOGGERTOINJECTINTOTHEHEROSERVICE", - "original": "If the app didn't provide this `Logger`,\nAngular would throw an exception when it looked for a `Logger` to inject\ninto the `HeroService`.", - "translation": "如果该应用没有提供这个 `Logger` 服务,当 Angular 试图把 `Logger` 注入到 `HeroService` 中时,就会抛出一个异常。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "BECAUSEASINGLETONLOGGERSERVICEISUSEFULEVERYWHEREITSPROVIDEDINTHEROOTAPPMODULE", - "original": "Because a singleton logger service is useful everywhere,\nit's provided in the root `AppModule`.", - "translation": "因为 `Logger` 服务的单例应该随处可用,所以要在根模块 `AppModule` 中提供它。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "THEINJECTABLEAPICOREINJECTABLEDECORATORIDENTIFIESASERVICECLASSTHATMIGHTREQUIREINJECTEDDEPENDENCIES", - "original": "The **[@Injectable()](api/core/Injectable)** decorator identifies a service class \nthat _might_ require injected dependencies.", - "translation": "**[@Injectable()](api/core/Injectable)** 装饰器表示*可能*需要往这个服务类中注入其它依赖。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "THEHEROSERVICEMUSTBEANNOTATEDWITHINJECTABLEBECAUSEITREQUIRESANINJECTEDLOGGER", - "original": "The `HeroService` must be annotated with `@Injectable()` because it requires an injected `Logger`.", - "translation": "`HeroService` 必须带有 `@Injectable()` 装饰器,因为它需要把 `Logger` 注入进来。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "ALWAYSWRITEINJECTABLEWITHPARENTHESESNOTJUSTINJECTABLE", - "original": "Always write `@Injectable()` with parentheses, not just `@Injectable`.", - "translation": "写 `@Injectable()` 时必须带括号,不能只写 `@Injectable`。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "WHENANGULARCREATESACLASSWHOSECONSTRUCTORHASPARAMETERSITLOOKSFORTYPEANDINJECTIONMETADATAABOUTTHOSEPARAMETERSSOTHATITCANINJECTTHERIGHTSERVICE", - "original": "When Angular creates a class whose constructor has parameters,\nit looks for type and injection metadata about those parameters\nso that it can inject the right service.", - "translation": "当 Angular 要创建一个构造函数中带参数的类时,会先查找这些参数的类型,以便根据这些参数的元数据注入正确的服务。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "IFANGULARCANTFINDTHATPARAMETERINFORMATIONITTHROWSANERROR", - "original": "If Angular can't find that parameter information, it throws an error.", - "translation": "如果不能找到该参数的信息,Angular 就会报错。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "ANGULARCANONLYFINDTHEPARAMETERINFORMATIONIFTHECLASSHASADECORATOROFSOMEKINDWHILEANYDECORATORWILLDOTHEINJECTABLEDECORATORISTHESTANDARDDECORATORFORSERVICECLASSES", - "original": "Angular can only find the parameter information _if the class has a decorator of some kind_.\nWhile _any_ decorator will do,\nthe `@Injectable()` decorator is the standard decorator for service classes.", - "translation": "Angular 只能在*带有某种装饰器的类*上查找参数信息。*任何*装饰器都可以,而 `@Injectable()` 装饰器是各种服务类的标准装饰器。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "THEDECORATORREQUIREMENTISIMPOSEDBYTYPESCRIPT", - "original": "The decorator requirement is imposed by TypeScript.", - "translation": "之所以必须有装饰器,是因为 TypeScript 强制要求的。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "TYPESCRIPTNORMALLYDISCARDSPARAMETERTYPEINFORMATIONWHENITTRANSPILESTHECODETOJAVASCRIPTITPRESERVESTHISINFORMATIONIFTHECLASSHASADECORATORANDTHEEMITDECORATORMETADATACOMPILEROPTIONISSETTRUEINTYPESCRIPTSTSCONFIGJSONCONFIGURATIONFILE", - "original": "TypeScript normally discards parameter type information when it _transpiles_ the code to JavaScript.\nIt preserves this information if the class has a decorator\nand the `emitDecoratorMetadata` compiler option is set `true` \nin TypeScript's `tsconfig.json` configuration file, .", - "translation": "当把 TypeScript 转译成 JavaScript 时,通常会丢弃参数的类型信息。\n但当该类带有装饰器并且当 `tsconfig.json` 配置文件中的 `emitDecoratorMetadata` 编译选项为 `true` 时,它就会保留这些信息。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "THECLICONFIGURESTSCONFIGJSONWITHEMITDECORATORMETADATA:TRUEITSYOURJOBTOPUTINJECTABLEONYOURSERVICECLASSES", - "original": "The CLI configures `tsconfig.json` with `emitDecoratorMetadata: true`\nIt's your job to put `@Injectable()` on your service classes.", - "translation": "CLI 生成的 `tsconfig.json` 中已经有 `emitDecoratorMetadata: true` 选项了,你只要把 `@Injectable()` 加到你的服务类上就可以了。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "THELOGGERSERVICEISANNOTATEDWITHINJECTABLEDECORATORTOOALTHOUGHITHASNOCONSTRUCTORANDNODEPENDENCIES", - "original": "The `Logger` service is annotated with `@Injectable()` decorator too, \nalthough it has no constructor and no dependencies.", - "translation": "`Logger` 服务也带有 `@Injectable()` 装饰器,不过它没有构造器,也没有依赖。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "INFACTEVERYANGULARSERVICECLASSINTHISAPPISANNOTATEDWITHTHEINJECTABLEDECORATORWHETHERORNOTITHASACONSTRUCTORANDDEPENDENCIESINJECTABLEISAREQUIREDCODINGSTYLEFORSERVICES", - "original": "In fact, _every_ Angular service class in this app is annotated with the `@Injectable()` decorator, whether or not it has a constructor and dependencies.\n`@Injectable()` is a required coding style for services.", - "translation": "该应用中的*每个* Angular 服务类不管有没有构造器和依赖,都带有 `@Injectable()` 装饰器。\n事实上,`@Injectable()` 是风格指南中对服务类的要求。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, { "key": "##PROVIDERS", "original": "## Providers", @@ -9731,12 +9515,6 @@ "translation": "在下面的几节中会解释指定提供商的多种方式。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, - { - "key": "ALMOSTALLOFTHEACCOMPANYINGCODESNIPPETSAREEXTRACTSFROMTHESAMPLEAPPSPROVIDERSCOMPONENTTSFILE", - "original": "Almost all of the accompanying code snippets are extracts from the sample app's `providers.component.ts` file.", - "translation": "几乎所有的代码片段都是从范例应用的 `providers.component.ts` 文件中提取出来的。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, { "key": "###THECLASSASITSOWNPROVIDER", "original": "### The class as its own provider", @@ -9983,6 +9761,264 @@ "translation": "在这个例子中,只在 `HeroesComponent` 中需要它,\n 这里,它代替了元数据 `providers` 数组中原来的 `HeroService` 注册。\n 对比一下新的和旧的实现:", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, + { + "key": "###TREESHAKABLEPROVIDERS", + "original": "### Tree-shakable providers", + "translation": "### 可以被摇树优化的提供商", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "TREESHAKINGISTHEABILITYTOREMOVECODETHATISNOTREFERENCEDINANAPPLICATIONFROMTHEFINALBUNDLETREESHAKABLEPROVIDERSGIVEANGULARTHEABILITYTOREMOVESERVICESTHATARENOTUSEDINYOURAPPLICATIONFROMTHEFINALOUTPUTTHISSIGNIFICANTLYREDUCESTHESIZEOFYOURBUNDLES", + "original": "Tree shaking is the ability to remove code that is not referenced in an application from the final bundle. Tree-shakable providers give Angular the ability to remove services that are not used in your application from the final output. This significantly reduces the size of your bundles.", + "translation": "摇树优化可以在最终打包时移除应用中从未引用过的代码。可摇树优化的提供商可以让 Angular 从结果中移除应用中那些从未使用过的服务。这可以显著减小打包体积。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "IDEALLYIFANAPPLICATIONISNOTINJECTINGASERVICEITSHOULDNOTBEINCLUDEDINTHEFINALOUTPUTHOWEVERITTURNSOUTTHATTHEANGULARCOMPILERCANNOTIDENTIFYATBUILDTIMEIFTHESERVICEWILLBEREQUIREDORNOTBECAUSEITSALWAYSPOSSIBLETOINJECTASERVICEDIRECTLYUSINGINJECTORGETSERVICEANGULARCANNOTIDENTIFYALLOFTHEPLACESINYOURCODEWHERETHISINJECTIONCOULDHAPPENSOITHASNOCHOICEBUTTOINCLUDETHESERVICEINTHEINJECTORREGARDLESSTHUSSERVICESPROVIDEDINMODULESARENOTTREESHAKEABLE", + "original": "Ideally, if an application is not injecting a service, it should not be included in the final output. However, it turns out that the Angular compiler cannot identify at build time if the service will be required or not. Because it's always possible to inject a service directly using `injector.get(Service)`, Angular cannot identify all of the places in your code where this injection could happen, so it has no choice but to include the service in the injector regardless. Thus, services provided in modules are not tree-shakeable.", + "translation": "理想情况下,如果应用没有注入过某个服务,它就不应该被包含在最终结果中。不过,问题在于 Angular 的编译器无法在构建期间识别出该服务是不是必要的。\n因为总是可以使用 `injector.get(Service)` 的形式直接注入某个服务,而 Angular 不能从你的代码中识别出所有能够进行这种注入的地方。所以,Angular 别无选择,只能把这个服务包含到注入器中。因此,在模块中提供的服务也就无法进行摇树优化了。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "LETUSCONSIDERANEXAMPLEOFNONTREESHAKABLEPROVIDERSINANGULAR", + "original": "Let us consider an example of non-tree-shakable providers in Angular.", + "translation": "来看一个 Angular 无法对提供商进行摇树优化的例子。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "INTHISEXAMPLETOPROVIDESERVICESINANGULARYOUINCLUDETHEMINANNGMODULE:", + "original": "In this example, to provide services in Angular, you include them in an `@NgModule`:", + "translation": "在这个例子中,为了在 Angular 中提供服务,你把它们都包含进了 `@NgModule` 中:", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "THISMODULECANTHENBEIMPORTEDINTOYOURAPPLICATIONMODULETOMAKETHESERVICEAVAILABLEFORINJECTIONINYOURAPP:", + "original": "This module can then be imported into your application module, to make the service available for injection in your app:", + "translation": "接着,该模块可以导入到你的应用模块中,以便让该服务在整个应用中可用:", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "WHENNGCRUNSITCOMPILESAPPMODULEINTOAMODULEFACTORYWHICHCONTAINSDEFINITIONSFORALLTHEPROVIDERSDECLAREDINALLTHEMODULESITINCLUDESATRUNTIMETHISFACTORYBECOMESANINJECTORTHATINSTANTIATESTHESESERVICES", + "original": "When `ngc` runs, it compiles AppModule into a module factory, which contains definitions for all the providers declared in all the modules it includes. At runtime, this factory becomes an injector that instantiates these services.", + "translation": "当运行 `ngc` 时,它会把 AppModule 编译进一个模块工厂里,该工厂中含有它包含的所有子模块中声明过的所有提供商。在运行期间,该工厂会编程一个用于实例化这些服务的注入器。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "TREESHAKINGDOESNTWORKINTHEMETHODABOVEBECAUSEANGULARCANNOTDECIDETOEXCLUDEONECHUNKOFCODETHEPROVIDERDEFINITIONFORTHESERVICEWITHINTHEMODULEFACTORYBASEDONWHETHERANOTHERCHUNKOFCODETHESERVICECLASSISUSEDTOMAKESERVICESTREESHAKEABLETHEINFORMATIONABOUTHOWTOCONSTRUCTANINSTANCEOFTHESERVICETHEPROVIDERDEFINITIONNEEDSTOBEAPARTOFTHESERVICECLASSITSELF", + "original": "Tree-shaking doesn't work in the method above because Angular cannot decide to exclude one chunk of code (the provider definition for the service within the module factory) based on whether another chunk of code (the service class) is used. To make services tree-shakeable, the information about how to construct an instance of the service (the provider definition) needs to be a part of the service class itself.", + "translation": "在这种方式下,摇树优化无法工作,因为 Angular 无法根据该代码(服务类)是否被其它代码块使用过(比如该服务的提供商就定义在了模块工厂里)来排除它。\n要让这些服务可以被摇树优化,所有关于如何构建该服务的实例的信息(提供商定义)就应该是该服务类本身的一部分。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "####CREATINGTREESHAKABLEPROVIDERS", + "original": "#### Creating tree-shakable providers", + "translation": "#### 创建可摇树优化的服务提供商", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "TOCREATEPROVIDERSTHATARETREESHAKABLETHEINFORMATIONTHATUSEDTOBESPECIFIEDINTHEMODULESHOULDBESPECIFIEDINTHEINJECTABLEDECORATORONTHESERVICEITSELF", + "original": "To create providers that are tree-shakable, the information that used to be specified in the module should be specified in the `@Injectable` decorator on the service itself.", + "translation": "要想创建可摇树优化的服务提供商,那些原本要通过模块来指定的信息就要改为在服务自身的 `@Injectable` 装饰器中提供。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "THEFOLLOWINGEXAMPLESHOWSTHETREESHAKEABLEEQUIVALENTTOTHESERVICEMODULEEXAMPLEABOVE:", + "original": "The following example shows the tree-shakeable equivalent to the `ServiceModule` example above:", + "translation": "下面的例子展示了一个与上面的 `ServiceModule` 范例等价的可摇树的优化版本:", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "INTHEEXAMPLEABOVEPROVIDEDINALLOWSYOUTODECLARETHEINJECTORWHICHINJECTSTHISSERVICEUNLESSTHEREISASPECIALCASETHEVALUESHOULDALWAYSBEROOTSETTINGTHEVALUETOROOTENSURESTHATTHESERVICEISSCOPEDTOTHEROOTINJECTORWITHOUTNAMINGAPARTICULARMODULETHATISPRESENTINTHATINJECTOR", + "original": "In the example above, `providedIn` allows you to declare the injector which injects this service. Unless there is a special case, the value should always be root. Setting the value to root ensures that the service is scoped to the root injector, without naming a particular module that is present in that injector.", + "translation": "上面这个例子中,`providedIn` 允许你声明要由哪个注入器来注入该服务。除了一些特殊情况外,这个值应该始终是 root(根注入器)。把该值设置为 root 可以确保该服务的范围是根注入器,而不是该注入器所在的那个特定模块。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "THESERVICECANBEINSTANTIATEDBYCONFIGURINGAFACTORYFUNCTIONASSHOWNBELOW:", + "original": "The service can be instantiated by configuring a factory function as shown below:", + "translation": "该服务也可以通过配置一个工厂函数来实例化,例子如下:", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "TOOVERRIDETREESHAKABLEPROVIDERSREGISTERTHEPROVIDERUSINGTHEPROVIDERS:ARRAYSYNTAXOFANYANGULARDECORATORTHATSUPPORTSIT", + "original": "To override tree-shakable providers, register the provider using the `providers: []` array syntax of any Angular decorator that supports it.", + "translation": "要想改写(override)一个可摇树优化的提供商,可以在任何支持 `providers: []` 数组的 Angular 装饰器中注册该提供商。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "##INJECTASERVICE", + "original": "## Inject a service", + "translation": "## 注入某个服务", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "THEHEROLISTCOMPONENTSHOULDGETHEROESFROMTHEHEROSERVICE", + "original": "The `HeroListComponent` should get heroes from the `HeroService`.", + "translation": "`HeroListComponent` 应该从 `HeroService` 中获取这些英雄数据。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "THECOMPONENTSHOULDNTCREATETHEHEROSERVICEWITHNEWITSHOULDASKFORTHEHEROSERVICETOBEINJECTED", + "original": "The component shouldn't create the `HeroService` with `new`.\nIt should ask for the `HeroService` to be injected.", + "translation": "该组件不应该使用 `new` 来创建 `HeroService`。\n它应该要求注入 `HeroService`。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "YOUCANTELLANGULARTOINJECTADEPENDENCYINTHECOMPONENTSCONSTRUCTORBYSPECIFYINGACONSTRUCTORPARAMETERWITHTHEDEPENDENCYTYPEHERESTHEHEROLISTCOMPONENTCONSTRUCTORASKINGFORTHEHEROSERVICETOBEINJECTED", + "original": "You can tell Angular to inject a dependency in the component's constructor by specifying a **constructor parameter with the dependency type**.\nHere's the `HeroListComponent` constructor, asking for the `HeroService` to be injected.", + "translation": "你可以通过**在构造函数中添加一个带有该依赖类型的参数**来要求 Angular 把这个依赖注入到组件的构造函数中。\n下面是 `HeroListComponent` 的构造函数,它要求注入 `HeroService`。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "OFCOURSETHEHEROLISTCOMPONENTSHOULDDOSOMETHINGWITHTHEINJECTEDHEROSERVICEHERESTHEREVISEDCOMPONENTMAKINGUSEOFTHEINJECTEDSERVICESIDEBYSIDEWITHTHEPREVIOUSVERSIONFORCOMPARISON", + "original": "Of course, the `HeroListComponent` should do something with the injected `HeroService`.\nHere's the revised component, making use of the injected service, side-by-side with the previous version for comparison.", + "translation": "当然,`HeroListComponent` 还应该使用注入的这个 `HeroService` 做点什么。\n下面输出修改过的组件,改用注入的服务,与前一个版本对比一下。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "NOTICETHATTHEHEROLISTCOMPONENTDOESNTKNOWWHERETHEHEROSERVICECOMESFROMYOUKNOWTHATITCOMESFROMTHEPARENTHEROESCOMPONENTIFYOUDECIDEDINSTEADTOPROVIDETHEHEROSERVICEINTHEAPPMODULETHEHEROLISTCOMPONENTWOULDNTCHANGEATALLTHEONLYTHINGTHATMATTERSISTHATTHEHEROSERVICEISPROVIDEDINSOMEPARENTINJECTOR", + "original": "Notice that the `HeroListComponent` doesn't know where the `HeroService` comes from.\n_You_ know that it comes from the parent `HeroesComponent`.\nIf you decided instead to provide the `HeroService` in the `AppModule`,\nthe `HeroListComponent` wouldn't change at all.\nThe _only thing that matters_ is that the `HeroService` is provided in some parent injector.", + "translation": "注意,`HeroListComponent` 并不知道 `HeroService` 来自哪里。\n不过,**你**知道它来自其父组件 `HeroesComponent`。\n如果你决定改为在 `AppModule` 中提供这个 `HeroService`,`HeroListComponent` 不需要做任何改动。\n**唯一需要关心的问题**是,`HeroService` 是由某个父注入器提供的。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "##SINGLETONSERVICES", + "original": "## Singleton services", + "translation": "## 单例服务", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "SERVICESARESINGLETONSWITHINTHESCOPEOFANINJECTORTHEREISATMOSTONEINSTANCEOFASERVICEINAGIVENINJECTOR", + "original": "Services are singletons _within the scope of an injector_.\nThere is at most one instance of a service in a given injector.", + "translation": "服务*在每个注入器的范围内*是单例的。\n在任何一个注入器中,最多只会有同一个服务的一个实例。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "THEREISONLYONEROOTINJECTORANDTHEUSERSERVICEISREGISTEREDWITHTHATINJECTORTHEREFORETHERECANBEJUSTONEUSERSERVICEINSTANCEINTHEENTIREAPPANDEVERYCLASSTHATINJECTSUSERSERVICEGETTHISSERVICEINSTANCE", + "original": "There is only one root injector, and the `UserService` is registered with that injector.\nTherefore, there can be just one `UserService` instance in the entire app,\nand every class that injects `UserService` get this service instance.", + "translation": "这里只有一个根注入器,而 `UserService` 就是在该注入器中注册的。\n所以,在整个应用中只能有一个 `UserService` 实例,每个要求注入 `UserService` 的类都会得到这个服务实例。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "HOWEVERANGULARDIISAHIERARCHICALINJECTIONSYSTEMGUIDEHIERARCHICALDEPENDENCYINJECTIONWHICHMEANSTHATNESTEDINJECTORSCANCREATETHEIROWNSERVICEINSTANCESANGULARCREATESNESTEDINJECTORSALLTHETIME", + "original": "However, Angular DI is a \n[hierarchical injection system](guide/hierarchical-dependency-injection), \nwhich means that nested injectors can create their own service instances.\nAngular creates nested injectors all the time.", + "translation": "不过,Angular DI 是一个 [多级注入系统](guide/hierarchical-dependency-injection),这意味着各级注入器都可以创建它们自己的服务实例。\nAngular 总会创建多级注入器。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "##COMPONENTCHILDINJECTORS", + "original": "## Component child injectors", + "translation": "## 组件的子注入器", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "COMPONENTINJECTORSAREINDEPENDENTOFEACHOTHERANDEACHOFTHEMCREATESITSOWNINSTANCESOFTHECOMPONENTPROVIDEDSERVICES", + "original": "Component injectors are independent of each other and\neach of them creates its own instances of the component-provided services.", + "translation": "组件注入器是彼此独立的,每一个都会为这些组件提供的服务创建单独的实例。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "FOREXAMPLEWHENANGULARCREATESANEWINSTANCEOFACOMPONENTTHATHASCOMPONENTPROVIDERSITALSOCREATESANEWCHILDINJECTORFORTHATINSTANCE", + "original": "For example, when Angular creates a new instance of a component that has `@Component.providers`,\nit also creates a new _child injector_ for that instance.", + "translation": "例如,当 Angular 创建一个带有 `@Component.providers` 的组件实例时,也会同时为这个实例创建一个新的*子注入器*。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "WHENANGULARDESTROYSONEOFTHESECOMPONENTINSTANCESITALSODESTROYSTHECOMPONENTSINJECTORANDTHATINJECTORSSERVICEINSTANCES", + "original": "When Angular destroys one of these component instances, it also destroys the\ncomponent's injector and that injector's service instances.", + "translation": "当 Angular 销毁某个组件实例时,也会同时销毁该组件的注入器,以及该注入器中的服务实例。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "BECAUSEOFINJECTORINHERITANCEGUIDEHIERARCHICALDEPENDENCYINJECTIONYOUCANSTILLINJECTAPPLICATIONWIDESERVICESINTOTHESECOMPONENTSACOMPONENTSINJECTORISACHILDOFITSPARENTCOMPONENTSINJECTORANDADESCENDENTOFITSPARENTSPARENTSINJECTORANDSOONALLTHEWAYBACKTOTHEAPPLICATIONSROOTINJECTORANGULARCANINJECTASERVICEPROVIDEDBYANYINJECTORINTHATLINEAGE", + "original": "Because of [injector inheritance](guide/hierarchical-dependency-injection),\nyou can still inject application-wide services into these components.\nA component's injector is a child of its parent component's injector,\nand a descendent of its parent's parent's injector, and so on all the way back to the application's _root_ injector.\nAngular can inject a service provided by any injector in that lineage.", + "translation": "由于是[多层注入器](guide/hierarchical-dependency-injection),因此你仍然可以把全应用级的服务注入到这些组件中。\n组件的注入器是其父组件注入器的孩子,也是其爷爷注入器的孙子,以此类推,直到该应用的**根**注入器。\nAngular 可以注入这条线上的任何注入器所提供的服务。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "FOREXAMPLEANGULARCOULDINJECTAHEROLISTCOMPONENTWITHBOTHTHEHEROSERVICEPROVIDEDINHEROCOMPONENTANDTHEUSERSERVICEPROVIDEDINAPPMODULE", + "original": "For example, Angular could inject a `HeroListComponent`\nwith both the `HeroService` provided in `HeroComponent`\nand the `UserService` provided in `AppModule`.", + "translation": "比如,Angular 可以把由 `HeroComponent` 提供的 `HeroService` 和由 `AppModule` 提供的 `UserService` 注入到 `HeroService` 中。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "##TESTINGTHECOMPONENT", + "original": "## Testing the component", + "translation": "## 测试组件", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "EARLIERYOUSAWTHATDESIGNINGACLASSFORDEPENDENCYINJECTIONMAKESTHECLASSEASIERTOTESTLISTINGDEPENDENCIESASCONSTRUCTORPARAMETERSMAYBEALLYOUNEEDTOTESTAPPLICATIONPARTSEFFECTIVELY", + "original": "Earlier you saw that designing a class for dependency injection makes the class easier to test.\nListing dependencies as constructor parameters may be all you need to test application parts effectively.", + "translation": "前面强调过,设计一个适合依赖注入的类,可以让这个类更容易测试。\n要有效的测试应用中的一部分,只需要在构造函数的参数中列出依赖。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "FOREXAMPLEYOUCANCREATEANEWHEROLISTCOMPONENTWITHAMOCKSERVICETHATYOUCANMANIPULATEUNDERTEST:", + "original": "For example, you can create a new `HeroListComponent` with a mock service that you can manipulate\nunder test:", + "translation": "例如,新建的 `HeroListComponent` 实例使用一个模拟 (mock) 服务,以便可以在测试中操纵它:", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "LEARNMOREINTHETESTINGGUIDETESTINGGUIDE", + "original": "Learn more in the [Testing](guide/testing) guide.", + "translation": "要学习更多知识,参见[测试](guide/testing)一章。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "##WHENTHESERVICENEEDSASERVICE", + "original": "## When the service needs a service", + "translation": "## 当服务需要别的服务时", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "THEHEROSERVICEISVERYSIMPLEITDOESNTHAVEANYDEPENDENCIESOFITSOWN", + "original": "The `HeroService` is very simple. It doesn't have any dependencies of its own.", + "translation": "这个 `HeroService` 非常简单。它本身不需要任何依赖。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "WHATIFITHADADEPENDENCYWHATIFITREPORTEDITSACTIVITIESTHROUGHALOGGINGSERVICEYOUDAPPLYTHESAMECONSTRUCTORINJECTIONPATTERNADDINGACONSTRUCTORTHATTAKESALOGGERPARAMETER", + "original": "What if it had a dependency? What if it reported its activities through a logging service?\nYou'd apply the same *constructor injection* pattern,\nadding a constructor that takes a `Logger` parameter.", + "translation": "如果它也有依赖,该怎么办呢?例如,它需要通过日志服务来汇报自己的活动。\n你同样用*构造函数注入*模式,来添加一个带有 `Logger` 参数的构造函数。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "HEREISTHEREVISEDHEROSERVICETHATINJECTSTHELOGGERSIDEBYSIDEWITHTHEPREVIOUSSERVICEFORCOMPARISON", + "original": "Here is the revised `HeroService` that injects the `Logger`, side-by-side with the previous service for comparison.", + "translation": "下面是修改后的 `HeroService`,它注入了 `Logger`,对比前后这两个版本:", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "THECONSTRUCTORASKSFORANINJECTEDINSTANCEOFALOGGERANDSTORESITINAPRIVATEFIELDCALLEDLOGGERTHEGETHEROESMETHODLOGSAMESSAGEWHENASKEDTOFETCHHEROES", + "original": "The constructor asks for an injected instance of a `Logger` and stores it in a private field called `logger`.\nThe `getHeroes()` method logs a message when asked to fetch heroes.", + "translation": "这个构造函数要求注入一个 `Logger` 类的实例,并把它存到名为 `logger` 的私有字段中。\n 当请求英雄数据时,`getHeroes()` 中就会记录一个消息。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "####THEDEPENDENTLOGGERSERVICE", + "original": "#### The dependent _Logger_ service", + "translation": "#### 被依赖的 `Logger` 服务", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "THESAMPLEAPPSLOGGERSERVICEISQUITESIMPLE:", + "original": "The sample app's `Logger` service is quite simple:", + "translation": "这个范例应用的 `Logger` 服务非常简单:", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "IFTHEAPPDIDNTPROVIDETHISLOGGERANGULARWOULDTHROWANEXCEPTIONWHENITLOOKEDFORALOGGERTOINJECTINTOTHEHEROSERVICE", + "original": "If the app didn't provide this `Logger`,\nAngular would throw an exception when it looked for a `Logger` to inject\ninto the `HeroService`.", + "translation": "如果该应用没有提供这个 `Logger` 服务,当 Angular 试图把 `Logger` 注入到 `HeroService` 中时,就会抛出一个异常。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, + { + "key": "BECAUSEASINGLETONLOGGERSERVICEISUSEFULEVERYWHEREITSPROVIDEDINTHEROOTAPPMODULE", + "original": "Because a singleton logger service is useful everywhere,\nit's provided in the root `AppModule`.", + "translation": "因为 `Logger` 服务的单例应该随处可用,所以要在根模块 `AppModule` 中提供它。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" + }, { "key": "##DEPENDENCYINJECTIONTOKENS", "original": "## Dependency injection tokens", @@ -10080,15 +10116,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "THETYPEPARAMETERWHILEOPTIONALCONVEYSTHEDEPENDENCYSTYPETODEVELOPERSANDTOOLINGTHETOKENDESCRIPTIONISANOTHERDEVELOPERAID", - "original": "The type parameter, while optional, conveys the dependency's type to developers and tooling.\nThe token description is another developer aid.", - "translation": "类型参数,虽然是可选的,但可以向开发者和开发工具传达类型信息。\n而且这个令牌的描述信息也可以为开发者提供帮助。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "REGISTERTHEDEPENDENCYPROVIDERUSINGTHEINJECTIONTOKENOBJECT:", - "original": "Register the dependency provider using the `InjectionToken` object:", - "translation": "使用这个 `InjectionToken` 对象注册依赖的提供商:", + "key": "YOUCANDIRECTLYCONFIGUREAPROVIDERWHENCREATINGANINJECTIONTOKENTHEPROVIDERCONFIGURATIONDETERMINESWHICHINJECTORPROVIDESTHETOKENANDHOWTHEVALUEWILLBECREATEDTHISISSIMILARTOUSINGINJECTABLEEXCEPTTHATYOUCANNOTDEFINESTANDARDPROVIDERSSUCHASUSECLASSORUSEFACTORYWITHINJECTIONTOKENINSTEADYOUSPECIFYAFACTORYFUNCTIONWHICHRETURNSTHEVALUETOBEPROVIDEDDIRECTLY", + "original": "You can directly configure a provider when creating an `InjectionToken`. The provider configuration determines which injector provides the token and how the value will be created. This is similar to using `@Injectable`, except that you cannot define standard providers (such as `useClass` or `useFactory`) with `InjectionToken`. Instead, you specify a factory function which returns the value to be provided directly.", + "translation": "你可以在创建 `InjectionToken` 时直接配置一个提供商。该提供商的配置会决定由哪个注入器来提供这个令牌,以及如何创建它的值。\n这和 `@Injectable` 的用法很像,不过你没法用 `InjectionToken` 来定义标准提供商(比如 `useClass` 或 `useFactory`),而要指定一个工厂函数,该函数直接返回想要提供的值。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { @@ -10098,15 +10128,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "ALTHOUGHTHEAPPCONFIGINTERFACEPLAYSNOROLEINDEPENDENCYINJECTIONITSUPPORTSTYPINGOFTHECONFIGURATIONOBJECTWITHINTHECLASS", - "original": "Although the `AppConfig` interface plays no role in dependency injection,\nit supports typing of the configuration object within the class.", - "translation": "虽然 `AppConfig` 接口在依赖注入过程中没有任何作用,但它为该类中的配置对象提供了强类型信息。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" - }, - { - "key": "ALTERNATIVELYYOUCANPROVIDEANDINJECTTHECONFIGURATIONOBJECTINANNGMODULELIKEAPPMODULE", - "original": "Alternatively, you can provide and inject the configuration object in an ngModule like `AppModule`.", - "translation": "或者在 ngModule 中提供并注入这个配置对象,如 `AppModule`。", + "key": "IFTHEFACTORYFUNCTIONNEEDSACCESSTOOTHERDITOKENSITCANUSETHEINJECTFUNCTIONFROMANGULARCORETOREQUESTDEPENDENCIES", + "original": "If the factory function needs access to other DI tokens, it can use the inject function from `@angular/core` to request dependencies.", + "translation": "如果工厂函数需要访问其它的 DI 令牌,它可以使用来自 `@angular/core` 中的 `inject` 函数来申请它的依赖。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { @@ -10116,15 +10140,15 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "THEHEROSERVICEREQUIRESALOGGERBUTWHATIFITCOULDGETBYWITHOUTALOGGERYOUCANTELLANGULARTHATTHEDEPENDENCYISOPTIONALBYANNOTATINGTHECONSTRUCTORARGUMENTWITHOPTIONAL:", - "original": "The `HeroService` *requires* a `Logger`, but what if it could get by without\na `logger`?\nYou can tell Angular that the dependency is optional by annotating the\nconstructor argument with `@Optional()`:", - "translation": "`HeroService`*需要*一个 `Logger`,但是如果想不提供 Logger 也能得到它,该怎么办呢?\n可以把构造函数的参数标记为 `@Optional()`,告诉 Angular 该依赖是可选的:", + "key": "YOUCANTELLANGULARTHATTHEDEPENDENCYISOPTIONALBYANNOTATINGTHECONSTRUCTORARGUMENTWITHNULL:", + "original": "You can tell Angular that the dependency is optional by annotating the constructor argument with null:", + "translation": "可以把构造函数的参数标记为 `null` 来告诉 Angular 该依赖是可选的:", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { - "key": "WHENUSINGOPTIONALYOURCODEMUSTBEPREPAREDFORANULLVALUEIFYOUDONTREGISTERALOGGERSOMEWHEREUPTHELINETHEINJECTORWILLSETTHEVALUEOFLOGGERTONULL", - "original": "When using `@Optional()`, your code must be prepared for a null value. If you\ndon't register a `logger` somewhere up the line, the injector will set the\nvalue of `logger` to null.", - "translation": "当使用 `@Optional()` 时,代码必须准备好如何处理空值。\n如果其它的代码没有注册一个 `logger`,注入器会设置该 `logger` 的值为空 null。", + "key": "WHENUSINGOPTIONALDEPENDENCIESYOURCODEMUSTBEPREPAREDFORANULLVALUE", + "original": "When using optional dependencies, your code must be prepared for a null value.", + "translation": "如果要使用可选依赖,你的代码就必须准备好处理空值。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dependency-injection.md" }, { @@ -10572,9 +10596,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/deployment.md" }, { - "key": "THEOUTPUTFOLDERISDISTBYDEFAULTTOOUTPUTTOADIFFERENTFOLDERCHANGETHEOUTDIRINANGULARCLIJSON", - "original": "The output folder is `dist/` by default.\nTo output to a different folder, change the `outDir` in `.angular-cli.json`.", - "translation": "默认的输出文件夹是 `dist/`。\n要输出到其它文件夹中,请修改 `.angular-cli.json` 中的 `outDir`。", + "key": "THEOUTPUTFOLDERISDISTBYDEFAULTTOOUTPUTTOADIFFERENTFOLDERCHANGETHEOUTPUTPATHINANGULARJSON", + "original": "The output folder is `dist/` by default.\nTo output to a different folder, change the `outputPath` in `angular.json`.", + "translation": "默认的输出文件夹是 `dist/`。\n要输出到其它文件夹中,请修改 `angular.json` 中的 `outputPath`。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/deployment.md" }, { @@ -11657,6 +11681,18 @@ "translation": "[回到顶部](guide/dynamic-form#top)", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/dynamic-form.md" }, + { + "key": "###HOWITWORKS", + "original": "### How it works", + "translation": "### 工作原理", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/elements.md" + }, + { + "key": "BROWSER", + "original": "Browser", + "translation": "浏览器", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/elements.md" + }, { "key": "#ENTRYCOMPONENTS", "original": "# Entry Components", @@ -13638,9 +13674,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "ANGULARHASITSOWNVOCABULARYMOSTANGULARTERMSARECOMMONENGLISHWORDSWITHASPECIFICMEANINGWITHINTHEANGULARSYSTEM", - "original": "Angular has its own vocabulary.\nMost Angular terms are common English words\nwith a specific meaning within the Angular system.", - "translation": "Angular 有自己的词汇表。\n虽然大多数 Angular 短语都是日常用语,但是在 Angular 体系中,它们有特别的含义。", + "key": "ANGULARHASITSOWNVOCABULARYMOSTANGULARTERMSARECOMMONENGLISHWORDSORCOMPUTINGTERMSTHATHAVEASPECIFICMEANINGWITHINTHEANGULARSYSTEM", + "original": "Angular has its own vocabulary.\nMost Angular terms are common English words or computing terms\nthat have a specific meaning within the Angular system.", + "translation": "Angular 有自己的词汇表。\n虽然大多数 Angular 短语都是日常用语或计算机术语,但是在 Angular 体系中,它们有特别的含义。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { @@ -13656,9 +13692,21 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "YOUCANCOMPILEANGULARAPPLICATIONSATBUILDTIMEBYCOMPILINGYOURAPPLICATIONUSINGTHECOMPILERCLINGCYOUCANBOOTSTRAPDIRECTLYTOAMODULEFACTORYMEANINGYOUDONTNEEDTOINCLUDETHEANGULARCOMPILERINYOURJAVASCRIPTBUNDLEAHEADOFTIMECOMPILEDAPPLICATIONSALSOBENEFITFROMDECREASEDLOADTIMEANDINCREASEDPERFORMANCE", - "original": "You can compile Angular applications at build time.\nBy compiling your application using the compiler-cli, `ngc`, you can bootstrap directly to a module factory, meaning you don't need to include the Angular compiler in your JavaScript bundle.\nAhead-of-time compiled applications also benefit from decreased load time and increased performance.", - "translation": "开发者可以在构造时 (build-time) 编译 Angular 应用程序。\n 通过 `compiler-cli` - `ngc` 编译应用程序,应用可以从一个模块工厂直接启动,\n 意味着不再需要把 Angular 编译器添加到 JavaScript 包中。\n 预编译的应用程序加载迅速,具有更高的性能。", + "key": "THEANGULARAHEADOFTIMEAOTCOMPILERCONVERTSYOURANGULARHTMLANDTYPESCRIPTCODEINTOEFFICIENTJAVASCRIPTCODEDURINGTHEBUILDPHASEBEFORETHEBROWSERDOWNLOADSANDRUNSTHATCODETHISISTHEBESTCOMPILATIONMODEFORPRODUCTIONENVIRONMENTSWITHDECREASEDLOADTIMEANDINCREASEDPERFORMANCE", + "original": "The Angular ahead-of-time (AOT) compiler converts your Angular HTML and TypeScript code \ninto efficient JavaScript code during the build phase before the browser downloads \nand runs that code. \nThis is the best compilation mode for production environments, with decreased load time and increased performance.", + "translation": "Angular 的预先(AOT)编译器可以在编译期间把你的 HTML 代码和 TypeScript 代码转换成高效的 JavaScript 代码,这样浏览器就可以直接下载和运行它们。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "BYCOMPILINGYOURAPPLICATIONUSINGTHENGCCOMMANDLINETOOLYOUCANBOOTSTRAPDIRECTLYTOAMODULEFACTORYMEANINGYOUDONTNEEDTOINCLUDETHEANGULARCOMPILERINYOURJAVASCRIPTBUNDLE", + "original": "By compiling your application using the `ngc` command-line tool, you can bootstrap directly to a module factory, meaning you don't need to include the Angular compiler in your JavaScript bundle.", + "translation": "使用命令行工具 `ngc` 来编译你的应用之后,就可以直接启动一个模块工厂,这意味着你不必再在 JavaScript 打包文件中包含 Angular 编译器。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "COMPAREJUSTINTIMEJITCOMPILATIONGUIDEGLOSSARY#JIT", + "original": "Compare [just-in-time (JIT) compilation](guide/glossary#jit).", + "translation": "可以与[即时(JIT)编译](guide/glossary#jit)对比一下。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { @@ -13668,9 +13716,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "INPRACTICEASYNONYMFORDECORATIONGUIDEGLOSSARY#DECORATOR", - "original": "In practice, a synonym for [Decoration](guide/glossary#decorator).", - "translation": "实际上,是[装饰 (decoration)](guide/glossary#decorator) 的同义词。", + "key": "ASTRUCTURETHATPROVIDESMETADATAFORACLASSSEEDECORATORGUIDEGLOSSARY#DECORATOR", + "original": "A structure that provides metadata for a class. See [Decorator](guide/glossary#decorator).", + "translation": "一种为类提供元数据的结构。参见 [装饰器](guide/glossary#decorator)。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { @@ -13686,63 +13734,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "FOREXAMPLEYOUCANUSETHENGCLASSDIRECTIVETOADDANDREMOVECSSCLASSNAMES", - "original": "For example, you can use the `ngClass` directive to add and remove CSS class names.", - "translation": "例如,`ngClass` 指令就是典型的属性型指令。它可以添加或移除 CSS 类名。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "LEARNABOUTTHEMINTHEATTRIBUTEDIRECTIVESGUIDEATTRIBUTEDIRECTIVESGUIDE", - "original": "Learn about them in the [_Attribute Directives_](guide/attribute-directives) guide.", - "translation": "要了解更多信息,请参见[*属性型指令*](guide/attribute-directives)页。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "##BARREL", - "original": "## Barrel", - "translation": "## 封装桶", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "AWAYTOROLLUPEXPORTSFROMSEVERALES2015MODULESINTOASINGLECONVENIENTES2015MODULETHEBARRELITSELFISANES2015MODULEFILETHATREEXPORTSSELECTEDEXPORTSOFOTHERES2015MODULES", - "original": "A way to *roll up exports* from several ES2015 modules into a single convenient ES2015 module.\nThe barrel itself is an ES2015 module file that re-exports *selected* exports of other ES2015 modules.", - "translation": "封装桶是把多个模块的*导出结果*汇总到单一的 ES2015 模块的一种方式。\n 封装桶本身是一个 ES2015 模块文件,它重新导出*选中的*导出,这些导入来自其它 ES2015 模块。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "FOREXAMPLEIMAGINETHREEES2015MODULESINAHEROESFOLDER:", - "original": "For example, imagine three ES2015 modules in a `heroes` folder:", - "translation": "例如,设想在 `heroes` 目录下有三个 ES2015 模块:", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "WITHOUTABARRELACONSUMERNEEDSTHREEIMPORTSTATEMENTS:", - "original": "Without a barrel, a consumer needs three import statements:", - "translation": "如果没有封装桶,消费者需要三条导入语句:", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "YOUCANADDABARRELTOTHEHEROESFOLDERCALLEDINDEXBYCONVENTIONTHATEXPORTSALLOFTHESEITEMS:", - "original": "You can add a barrel to the `heroes` folder (called `index`, by convention) that exports all of these items:", - "translation": "在 `heroes` 目录下添加一个封装桶(按约定叫做 `index`),它导出所有这三项:", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "NOWACONSUMERCANIMPORTWHATITNEEDSFROMTHEBARREL", - "original": "Now a consumer can import what it needs from the barrel.", - "translation": "现在,消费者就就可以从这个封装桶中导入它需要的东西了。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "THEANGULARSCOPEDPACKAGESGUIDEGLOSSARY#SCOPEDPACKAGEEACHHAVEABARRELNAMEDINDEX", - "original": "The Angular [scoped packages](guide/glossary#scoped-package) each have a barrel named `index`.", - "translation": "Angular 的每个[范围化包 (scoped package)](guide/glossary#scoped-package) 都有一个名为 `index` 的封装桶。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "YOUCANOFTENACHIEVETHESAMERESULTUSINGNGMODULESGUIDEGLOSSARY#NGMODULEINSTEAD", - "original": "You can often achieve the same result using [NgModules](guide/glossary#ngmodule) instead.", - "translation": "注意,你可以利用 [Angular 模块](guide/glossary#ngmodule)达到同样的目的。", + "key": "LEARNMOREINTHEATTRIBUTEDIRECTIVESGUIDEATTRIBUTEDIRECTIVESGUIDE", + "original": "Learn more in the [_Attribute Directives_](guide/attribute-directives) guide.", + "translation": "要了解更多,参见[*属性型指令*](guide/attribute-directives)", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { @@ -13752,15 +13746,15 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "USUALLYREFERSTODATABINDINGGUIDEGLOSSARY#DATABINDINGANDTHEACTOFBINDINGANHTMLOBJECTPROPERTYTOADATAOBJECTPROPERTY", - "original": "Usually refers to [data binding](guide/glossary#data-binding) and the act of\nbinding an HTML object property to a data object property.", - "translation": "几乎都是指的[数据绑定 (data binding)](guide/glossary#data-binding) 和将 HTML 对象属性绑定到数据对象属性的行为。", + "key": "GENERALLYTHEPRACTICEOFSETTINGAVARIABLEORPROPERTYTOADATAVALUEWITHINANGULARTYPICALLYREFERSTODATABINDINGGUIDEGLOSSARY#DATABINDINGWHICHCOORDINATESDOMOBJECTPROPERTIESWITHDATAOBJECTPROPERTIES", + "original": "Generally, the practice of setting a variable or property to a data value. \nWithin Angular, typically refers to [data binding](guide/glossary#data-binding), \nwhich coordinates DOM object properties with data object properties.", + "translation": "广义上是指把变量或属性设置为某个数据值的一种实践。\n在 Angular 中,一般是指[数据绑定](guide/glossary#data-binding),它会根据数据对象属性的值来设置 DOM 对象的属性。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "SOMETIMESREFERSTOADEPENDENCYINJECTIONGUIDEGLOSSARY#DEPENDENCYINJECTIONBINDINGBETWEENATOKENMDASHALSOREFERREDTOASAKEYMDASHANDADEPENDENCYPROVIDERGUIDEGLOSSARY#PROVIDER", - "original": "Sometimes refers to a [dependency-injection](guide/glossary#dependency-injection) binding\nbetween a \"token\"—also referred to as a \"key\"—and a dependency [provider](guide/glossary#provider).", - "translation": "有时也会指在“令牌”(也称为键)和依赖[提供商 (provider)](guide/glossary#provider)\n之间的[依赖注入 (dependency injection)](guide/glossary#dependency-injection) 绑定。\n这种用法很少,而且一般都会在上下文中写清楚。", + "key": "SOMETIMESREFERSTOADEPENDENCYINJECTIONGUIDEGLOSSARY#DEPENDENCYINJECTIONBINDINGBETWEENATOKENGUIDEGLOSSARY#TOKENANDADEPENDENCYPROVIDERGUIDEGLOSSARY#PROVIDER", + "original": "Sometimes refers to a [dependency-injection](guide/glossary#dependency-injection) binding\nbetween a [token](guide/glossary#token) and a dependency [provider](guide/glossary#provider).", + "translation": "有时也会指在“[令牌(Token)](guide/glossary#token)”和依赖[提供商(Provider)](guide/glossary#provider)\n之间的[依赖注入](guide/glossary#dependency-injection) 绑定。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { @@ -13770,51 +13764,99 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "YOULAUNCHANANGULARAPPLICATIONBYBOOTSTRAPPINGITUSINGTHEAPPLICATIONROOTNGMODULEAPPMODULE", - "original": "You launch an Angular application by \"bootstrapping\" it using the application root NgModule (`AppModule`).", - "translation": "通过应用程序根 Angular 模块(`AppModule`)来启动 Angular 应用程序。", + "key": "AWAYTOINITIALIZEANDLAUNCHANAPPORSYSTEM", + "original": "A way to initialize and launch an app or system.", + "translation": "一种用来初始化和启动应用或系统的途径。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "BOOTSTRAPPINGIDENTIFIESANAPPLICATIONSTOPLEVELROOTCOMPONENTGUIDEGLOSSARY#COMPONENTWHICHISTHEFIRSTCOMPONENTTHATISLOADEDFORTHEAPPLICATION", - "original": "Bootstrapping identifies an application's top level \"root\" [component](guide/glossary#component),\nwhich is the first component that is loaded for the application.", - "translation": "启动过程标识应用的顶级“根”[组件 (component)](guide/glossary#component),也就是应用加载的第一个组件。", + "key": "INANGULARANAPPSROOTNGMODULEAPPMODULEHASABOOTSTRAPPROPERTYTHATIDENTIFIESTHEAPPSTOPLEVELCOMPONENTSGUIDEGLOSSARY#COMPONENTDURINGTHEBOOTSTRAPPROCESSANGULARCREATESANDINSERTSTHESECOMPONENTSINTOTHEINDEXHTMLHOSTWEBPAGEYOUCANBOOTSTRAPMULTIPLEAPPSINTHESAMEINDEXHTMLEACHAPPWITHITSOWNCOMPONENTS", + "original": "In Angular, an app's root NgModule (`AppModule`) has a `bootstrap` property that identifies the app's top-level [components](guide/glossary#component). \nDuring the bootstrap process, Angular creates and inserts these components into the `index.html` host web page. \nYou can bootstrap multiple apps in the same `index.html`, each app with its own components.", + "translation": "在 Angular 中,应用的根模块(`AppModule`)有一个 `bootstrap` 属性,用于指出该应用的的顶级[组件](guide/glossary#component)。\n在引导期间,Angular 会创建这些组件,并插入到宿主页面 `index.html` 中。\n你可以在同一个 `index.html` 中引导多个应用,每个应用都有一些自己的组件。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "YOUCANBOOTSTRAPMULTIPLEAPPSINTHESAMEINDEXHTMLEACHAPPWITHITSOWNTOPLEVELROOT", - "original": "You can bootstrap multiple apps in the same `index.html`, each app with its own top-level root.", - "translation": "你可以在同一个 `index.html` 中引导多个应用,每个应用都有它自己的顶级根组件。", + "key": "LEARNMOREINTHEBOOTSTRAPPINGGUIDEBOOTSTRAPPINGGUIDE", + "original": "Learn more in the [_Bootstrapping_](guide/bootstrapping) guide.", + "translation": "要了解更多,参见[*引导*](guide/bootstrapping)一章。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "##CAMELCASE", - "original": "## camelCase", - "translation": "## 驼峰式命名法 (camelCase)", + "key": "##CASECONVENTIONS", + "original": "## Case conventions", + "translation": "## 大小写约定", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "THEPRACTICEOFWRITINGCOMPOUNDWORDSORPHRASESSUCHTHATEACHWORDORABBREVIATIONBEGINSWITHACAPITALLETTEREXCEPTTHEFIRSTLETTERWHICHISLOWERCASE", - "original": "The practice of writing compound words or phrases such that each word or abbreviation begins with a capital letter\n_except the first letter, which is lowercase_.", - "translation": "驼峰式命名法是书写复合词或短语的一种形式,除首字母要小写外,每个单词或缩写都以大写字母开头。", + "key": "ANGULARUSESCAPITALIZATIONCONVENTIONSTODISTINGUISHTHENAMESOFVARIOUSTYPESASDESCRIBEDINTHESTYLEGUIDENAMINGSECTIONGUIDESTYLEGUIDE#0201", + "original": "Angular uses capitalization conventions to distinguish the names of various types, as described in the [Style Guide \"Naming\" section](guide/styleguide#02-01).", + "translation": "Angular 使用大小写约定来区分多种名字,详见[风格指南中的 \"命名\" 一节](guide/styleguide#02-01)。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "FUNCTIONPROPERTYANDMETHODNAMESARETYPICALLYSPELLEDINCAMELCASEFOREXAMPLESQUAREFIRSTNAMEANDGETHEROESNOTICETHATSQUAREISANEXAMPLEOFHOWYOUWRITEASINGLEWORDINCAMELCASE", - "original": "Function, property, and method names are typically spelled in camelCase. For example, `square`, `firstName`, and `getHeroes`. Notice that `square` is an example of how you write a single word in camelCase.", - "translation": "通常,函数、属性和方法命名使用驼峰式拼写法。例如,`square`, `firstName` 和 `getHeroes`。注意这里的 `square` 是如何用驼峰式命名法表示单一词的例子。", + "key": "CAMELCASE:SYMBOLSPROPERTIESMETHODSPIPENAMESNONCOMPONENTDIRECTIVESELECTORSCONSTANTS", + "original": "- camelCase : symbols, properties, methods, pipe names, non-component directive selectors, constants", + "translation": "小驼峰形式(camelCase):符号、属性、方法、管道名、非组件指令的选择器、常量。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "CAMELCASEISALSOKNOWNASLOWERCAMELCASETODISTINGUISHITFROMUPPERCAMELCASEORPASCALCASEGUIDEGLOSSARY#PASCALCASEINANGULARDOCUMENTATIONCAMELCASEALWAYSMEANSLOWERCAMELCASE", - "original": "camelCase is also known as *lower camel case* to distinguish it from *upper camel case*, or [PascalCase](guide/glossary#pascalcase).\nIn Angular documentation, \"camelCase\" always means *lower camel case*.", - "translation": "这种形式也叫做**小写驼峰式命名法 (lower camel case)**,以区分于**大写驼峰式命名法**,也称 [Pascal 命名法 (PascalCase)](guide/glossary#pascalcase)。\nAngular 文档中提到“驼峰式命名法 (camelCase) ”的时候,所指的都是小驼峰命名法。", + "key": "UPPERCAMELCASEORPASCALCASE:CLASSNAMESINCLUDINGCLASSESTHATDEFINECOMPONENTSINTERFACESNGMODULESDIRECTIVESPIPESANDSOON", + "original": "- UpperCamelCase (or PascalCase): Class names, including classes that define components, interfaces, NgModules, directives, pipes, and so on.", + "translation": "大驼峰形式(UpperCamelCase)或叫帕斯卡形式(PascalCase):类名(也包括用来定义组件、接口、NgModule、指令、管道等的类)。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "THEANGULARCLIISACOMMANDLINEINTERFACETOOLTHATCANCREATEAPROJECTADDFILESANDPERFORMAVARIETYOFONGOINGDEVELOPMENTTASKSSUCHASTESTINGBUNDLINGANDDEPLOYMENT", - "original": "The Angular CLI is a `command line interface` tool that can create a project, add files, and perform a variety of ongoing development tasks such as testing, bundling, and deployment.", - "translation": "Angular CLI 是个命令行接口(Command Line Interface)工具,它可以创建项目、添加文件以及执行各种正在进行的开发任务,比如测试、打包和部署。", + "key": "DASHCASEORKEBABCASE:DESCRIPTIVEPARTOFFILENAMESCOMPONENTSELECTORS", + "original": "- dash-case (or \"kebab-case\"): descriptive part of file names, component selectors", + "translation": "中线形式(dash-case)或叫烤串形式(kebab-case):文件名中的描述部分,组件的选择器", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "UNDERSCORECASEORSNAKECASE:NOTTYPICALLYUSEDINANGULAR", + "original": "- underscore_case (or \"snake_case\"): not typically used in Angular", + "translation": "下划线形式(underscore_case)或叫蛇形形式(snake_case):在 Angular 中没有典型用法。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "UPPERUNDERSCORECASEORUPPERSNAKECASE:TRADITIONALFORCONSTANTSACCEPTABLEBUTPREFERCAMELCASE", + "original": "- UPPER_UNDERSCORE_CASE (or UPPER_SNAKE_CASE): traditional for constants (acceptable, but prefer camelCase)", + "translation": "大写下划线形式(UPPER_UNDERSCORE_CASE)或叫大写蛇形形式(UPPER_SNAKE_CASE):传统的常量写法(可以接受,但更推荐用小驼峰形式(camelCase))", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "##CLASSDECORATOR", + "original": "## Class decorator", + "translation": "## 类装饰器", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "ADECORATORGUIDEGLOSSARY#DECORATORSTATEMENTIMMEDIATELYBEFOREACLASSDEFINITIONTHATDECLARESTHECLASSTOBEOFTHEGIVENTYPEANDPROVIDESMETADATASUITABLETOTHETYPE", + "original": "A [decorator](guide/glossary#decorator) statement immediately before a class definition that declares the class to be of the given type, and provides metadata suitable to the type.", + "translation": "出现在类定义紧前方的[装饰器](guide/glossary#decorator)语句用来声明该类具有指定的类型,并且提供适合该类型的元数据。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "THEFOLLOWINGCLASSTYPESCANBEDECLARED:", + "original": "The following class types can be declared:", + "translation": "可以声明为下列类型之一:", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "##CLASSFIELDDECORATOR", + "original": "## Class field decorator", + "translation": "## 类字段装饰器", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "ADECORATORGUIDEGLOSSARY#DECORATORSTATEMENTIMMEDIATELYBEFOREAFIELDINACLASSDEFINITIONTHATDECLARESTHETYPEOFTHATFIELDSOMEEXAMPLESAREINPUTANDOUTPUT", + "original": "A [decorator](guide/glossary#decorator) statement immediately before a field in a class definition that declares the type of that field. Some examples are `@Input` and `@Output`.", + "translation": "出现在类定义中属性紧前方的[装饰器](guide/glossary#decorator)语句用来声明该字段的类型。比如 `@Input` 和 `@Output`。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "THEANGULARCLIHTTPS:CLIANGULARIOISACOMMANDLINETOOLTHATCANCREATEAPROJECTADDFILESANDPERFORMAVARIETYOFONGOINGDEVELOPMENTTASKSSUCHASTESTINGBUNDLINGANDDEPLOYMENT", + "original": "The [Angular CLI](https://cli.angular.io/) is a command-line tool that can create a project, add files, and perform a variety of ongoing development tasks such as testing, bundling, and deployment.", + "translation": "[Angular CLI](https://cli.angular.io/) 是个命令行(Command Line Interface)工具,它可以创建项目、添加文件以及执行各种正在进行的开发任务,比如测试、打包和部署。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { @@ -13830,45 +13872,57 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "ANANGULARCLASSRESPONSIBLEFOREXPOSINGDATATOAVIEWGUIDEGLOSSARY#VIEWANDHANDLINGMOSTOFTHEVIEWSDISPLAYANDUSERINTERACTIONLOGIC", - "original": "An Angular class responsible for exposing data to a [view](guide/glossary#view) and handling most of the view’s display and user-interaction logic.", - "translation": "组件是一个 Angular 类,用于把数据展示到[视图 (view)](guide/glossary#view),并处理几乎所有的视图显示和交互逻辑。", + "key": "ACLASSWITHTHECOMPONENTDECORATORGUIDEGLOSSARY#DECORATORTHATASSOCIATESITWITHACOMPANIONTEMPLATEGUIDEGLOSSARY#TEMPLATE", + "original": "A class with the `@Component` [decorator](guide/glossary#decorator) that associates it with a companion [template](guide/glossary#template).", + "translation": "一个带有 `@Component` [装饰器](guide/glossary#decorator)的类,用来为它关联一个与之相伴的[模板](guide/glossary#template)。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "THECOMPONENTISONEOFTHEMOSTIMPORTANTBUILDINGBLOCKSINTHEANGULARSYSTEMITISINFACTANANGULARDIRECTIVEGUIDEGLOSSARY#DIRECTIVEWITHACOMPANIONTEMPLATEGUIDEGLOSSARY#TEMPLATE", - "original": "The *component* is one of the most important building blocks in the Angular system.\nIt is, in fact, an Angular [directive](guide/glossary#directive) with a companion [template](guide/glossary#template).", - "translation": "*组件*是 Angular 系统中最重要的基本构造块之一。\n它其实是一个拥有[模板 (template)](guide/glossary#template)的[指令 (directive)](guide/glossary#directive)。", + "key": "ACOMPONENTISASPECIALTYPEOFDIRECTIVEGUIDEGLOSSARY#DIRECTIVETHATREPRESENTSAVIEWGUIDEGLOSSARY#VIEWTHECOMPONENTDECORATOREXTENDSTHEDIRECTIVEDECORATORWITHTEMPLATEORIENTEDFEATURES", + "original": "A component is a special type of [directive](guide/glossary#directive) that represents a [view](guide/glossary#view).The `@Component` decorator extends the `@Directive` decorator with template-oriented features.", + "translation": "组件是[指令](guide/glossary#directive)的一种特例,它表示一个[视图](guide/glossary#view)。`@Component` 装饰器扩展了 `@Directive` 装饰器,增加了一些与模板有关的特性。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "APPLYTHECOMPONENTDECORATORGUIDEGLOSSARY#DECORATORTOTHECOMPONENTCLASSTHEREBYATTACHINGTOTHECLASSTHEESSENTIALCOMPONENTMETADATATHATANGULARNEEDSTOCREATEACOMPONENTINSTANCEANDRENDERTHECOMPONENTWITHITSTEMPLATEASAVIEW", - "original": "Apply the `@Component` [decorator](guide/glossary#decorator) to\nthe component class, thereby attaching to the class the essential component metadata\nthat Angular needs to create a component instance and render the component with its template\nas a view.", - "translation": "需要将 `#@Component`[装饰器](guide/glossary#decorator)应用到一个组件类,从而把必要的组件元数据附加到类上。\nAngular 会需要元数据来创建一个组件实例,并把组件的模板作为视图渲染出来。", + "key": "ANANGULARCOMPONENTCLASSISRESPONSIBLEFOREXPOSINGDATAANDHANDLINGMOSTOFTHEVIEWSDISPLAYANDUSERINTERACTIONLOGICTHROUGHDATABINDINGGUIDEGLOSSARY#DATABINDING", + "original": "An Angular component class is responsible for exposing data and handling most of the view's display and user-interaction logic through [data binding](guide/glossary#data-binding).", + "translation": "Angular 的组件类负责暴露数据,并通过[数据绑定机制](guide/glossary#data-binding)来处理绝大多数视图的显示和用户交互逻辑。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "THOSEFAMILIARWITHMVCANDMVVMPATTERNSWILLRECOGNIZETHECOMPONENTINTHEROLEOFCONTROLLERORVIEWMODEL", - "original": "Those familiar with \"MVC\" and \"MVVM\" patterns will recognize\nthe component in the role of \"controller\" or \"view model\".", - "translation": "如果你熟悉 \"MVC\" 和 \"MVVM\" 模式,就会意识到组件充当了“控制器 (controller) ”和“视图模型 (view model) ”的角色。", + "key": "READMOREABOUTCOMPONENTSTEMPLATESANDVIEWSINTHEARCHITECTUREGUIDEARCHITECTUREGUIDE", + "original": "Read more about components, templates, and views in the [Architecture](guide/architecture) guide.", + "translation": "要了解更多关于组件、模板和视图的知识,参见 [架构](guide/architecture) 一章。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "##DASHCASE", - "original": "## dash-case", - "translation": "## 中线命名法 (dash-case)", + "key": "##CUSTOMELEMENT", + "original": "## Custom element", + "translation": "## 自定义元素", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "THEPRACTICEOFWRITINGCOMPOUNDWORDSORPHRASESSUCHTHATEACHWORDISSEPARATEDBYADASHORHYPHENTHISFORMISALSOKNOWNASKEBABCASE", - "original": "The practice of writing compound words or phrases such that each word is separated by a dash or hyphen (`-`).\nThis form is also known as kebab-case.", - "translation": "中线命名法是书写复合词或短语的一种形式,使用中线 (`-`) 分隔每个单词。\n这种形式也称为烤串命名法 kebab-case。", + "key": "AWEBPLATFORMFEATURECURRENTLYSUPPORTEDBYMOSTBROWSERSANDAVAILABLEINOTHERBROWSERSTHROUGHPOLYFILLSSEEBROWSERSUPPORTGUIDEBROWSERSUPPORT", + "original": "A Web Platform feature, currently supported by most browsers, and available in other browsers through polyfills (see [Browser Support](guide/browser-support)).", + "translation": "一种 Web 平台的特性,目前已经被绝大多数浏览器支持,在其它浏览器中也可以通过腻子脚本获得支持(参见[浏览器支持](guide/browser-support))。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "DIRECTIVEGUIDEGLOSSARY#DIRECTIVESELECTORSLIKEMYAPPANDTHEROOTOFFILENAMESSUCHASHEROLISTCOMPONENTTSAREOFTENSPELLEDINDASHCASE", - "original": "[Directive](guide/glossary#directive) selectors (like `my-app`) and\nthe root of filenames (such as `hero-list.component.ts`) are often\nspelled in dash-case.", - "translation": "[指令](guide/glossary#directive)的选择器(例如 `my-app`)和文件名(例如 `hero-list.component.ts`)通常是用中线命名法来命名。", + "key": "THECUSTOMELEMENTFEATUREEXTENDSHTMLBYALLOWINGYOUTODEFINEATAGWHOSECONTENTISCREATEDANDCONTROLLEDBYJAVASCRIPTCODEACUSTOMELEMENTALSOCALLEDAWEBCOMPONENTISRECOGNIZEDBYABROWSERWHENITISADDEDTOTHECUSTOMELEMENTREGISTRYHTTPS:DEVELOPERMOZILLAORGENUSDOCSWEBAPICUSTOMELEMENTREGISTRY", + "original": "The custom element feature extends HTML by allowing you to define a tag whose content is created and controlled by JavaScript code. A custom element (also called a *web component*) is recognized by a browser when it is added to the [CustomElementRegistry](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry).", + "translation": "这种自定义元素特性通过允许你定义标签(其内容是由 JavaScript 代码来创建和控制的)来扩展 HTML。当自定义元素(也叫 *Web Component*)被添加到 [CustomElementRegistry](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry) 之后就会被浏览器识别。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "YOUCANUSETHEAPITOTRANSFORMANANGULARCOMPONENTSOTHATITCANBEREGISTEREDWITHTHEBROWSERANDUSEDINANYHTMLTHATYOUADDDIRECTLYTOTHEDOMWITHINANANGULARAPPTHECUSTOMELEMENTTAGINSERTSTHECOMPONENTSVIEWWITHCHANGEDETECTIONANDDATABINDINGFUNCTIONALITYINTOCONTENTTHATWOULDOTHERWISEBEDISPLAYEDWITHOUTANGULARPROCESSING", + "original": "You can use the API to transform an Angular component so that it can be registered with the browser and used in any HTML that you add directly to the DOM within an Angular app. The custom element tag inserts the component's view, with change-detection and data-binding functionality, into content that would otherwise be displayed without Angular processing.", + "translation": "你可以使用 API 来转换 Angular 组件,以便它能够注册进浏览器中,并且可以用在你往 DOM 中添加的任意 HTML 中。\n自定义元素标签可以把组件的视图(包括变更检测和数据绑定功能)插入到不受 Angular 控制的内容中。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "SEEALSODYNAMICCOMPONENTSGUIDEGLOSSARY#DYNAMICCOMPONENTS", + "original": "See also [Dynamic components](guide/glossary#dynamic-components).", + "translation": "参见[动态组件](guide/glossary#dynamic-components)。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { @@ -13878,9 +13932,9 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "APPLICATIONSDISPLAYDATAVALUESTOAUSERANDRESPONDTOUSERACTIONSSUCHASCLICKSTOUCHESANDKEYSTROKES", - "original": "Applications display data values to a user and respond to user\nactions (such as clicks, touches, and keystrokes).", - "translation": "应用程序会将数据展示给用户,并对用户的操作(点击、触屏、按键)做出回应。", + "key": "DATABINDINGALLOWAPPSTODISPLAYDATAVALUESTOAUSERANDRESPONDTOUSERACTIONSSUCHASCLICKSTOUCHESANDKEYSTROKES", + "original": "Data binding allow apps to display data values to a user and respond to user\nactions (such as clicks, touches, and keystrokes).", + "translation": "数据绑定允许应用程序将数据展示给用户,并对用户的操作(点击、触屏、按键)做出回应。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { @@ -13889,12 +13943,6 @@ "translation": "在数据绑定机制下,你只要声明一下 HTML 部件和数据源之间的关系,把细节交给框架去处理。\n而以前的手动操作过程是:将数据推送到 HTML 页面中、添加事件监听器、从屏幕获取变化后的数据,并更新应用中的值。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, - { - "key": "ANGULARHASARICHDATABINDINGFRAMEWORKWITHAVARIETYOFDATABINDINGOPERATIONSANDSUPPORTINGDECLARATIONSYNTAX", - "original": "Angular has a rich data-binding framework with a variety of data-binding\noperations and supporting declaration syntax.", - "translation": "Angular 有一个非常强大的数据绑定框架,具有各种数据绑定操作,并支持声明式语法。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, { "key": "READABOUTTHEFOLLOWINGFORMSOFBINDINGINTHETEMPLATESYNTAXGUIDETEMPLATESYNTAXPAGE:", "original": "Read about the following forms of binding in the [Template Syntax](guide/template-syntax) page:", @@ -13943,6 +13991,60 @@ "translation": "[基于 ngModel 的双向数据绑定 (Two-way data binding with ngModel)](guide/template-syntax#ngModel)。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, + { + "key": "##DECLARABLE", + "original": "## Declarable", + "translation": "## 可声明对象", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "ACLASSTYPETHATYOUCANADDTOTHEDECLARATIONSLISTOFANNGMODULEGUIDEGLOSSARY#NGMODULE", + "original": "A class type that you can add to the `declarations` list of an [NgModule](guide/glossary#ngmodule).", + "translation": "类的一种类型,你可以把它们添加到 [NgModule](guide/glossary#ngmodule) 的 `declarations` 列表中。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "YOUCANDECLARECOMPONENTSGUIDEGLOSSARY#COMPONENTDIRECTIVESGUIDEGLOSSARY#DIRECTIVEANDPIPESGUIDEGLOSSARY#PIPE", + "original": "You can declare [components](guide/glossary#component), [directives](guide/glossary#directive), and [pipes](guide/glossary#pipe).", + "translation": "你可以声明[组件](guide/glossary#component)、[指令](guide/glossary#directive)和[管道](guide/glossary#pipe)。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "DONOTDECLARETHEFOLLOWING:", + "original": "Do not declare the following:", + "translation": "*不要*声明:", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "ACLASSTHATSALREADYDECLAREDINANOTHERNGMODULE", + "original": "- A class that's already declared in another NgModule.", + "translation": "已经在其它 NgModule 中声明过的类。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "ANARRAYOFDIRECTIVESIMPORTEDFROMANOTHERPACKAGEFOREXAMPLEDONTDECLAREFORMSDIRECTIVESFROMANGULARFORMS", + "original": "- An array of directives imported from another package. For example, don't declare `FORMS_DIRECTIVES` from `@angular/forms`.", + "translation": "从其它包中导入的指令数组。比如,不要再次声明来自 `@angular/forms` 中的 `FORMS_DIRECTIVES`。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "NGMODULECLASSES", + "original": "- NgModule classes.", + "translation": "NgModule 类。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "SERVICECLASSES", + "original": "- Service classes.", + "translation": "服务类", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, + { + "key": "NONANGULARCLASSESANDOBJECTSSUCHASSTRINGSNUMBERSFUNCTIONSENTITYMODELSCONFIGURATIONSBUSINESSLOGICANDHELPERCLASSES", + "original": "- Non-Angular classes and objects, such as strings, numbers, functions, entity models, configurations, business logic, and helper classes", + "translation": "非 Angular 的类和对象,比如:字符串、数字、函数、实体模型、配置、业务逻辑和辅助类。", + "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" + }, { "key": "##DECORATORDECORATION", "original": "## Decorator | decoration", @@ -13950,39 +14052,21 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "AFUNCTIONTHATADDSMETADATATOACLASSITSMEMBERSPROPERTIESMETHODSANDFUNCTIONARGUMENTS", - "original": "A *function* that adds metadata to a class, its members (properties, methods) and function arguments.", - "translation": "装饰器是一个**函数**,它将元数据添加到类、类成员(属性、方法)和函数参数。", + "key": "AFUNCTIONTHATMODIFIESTHEIMMEDIATELYFOLLOWINGCLASSORPROPERTYDEFINITIONDECORATORSALSOCALLEDANNOTATIONSAREANEXPERIMENTALSTAGE2JAVASCRIPTLANGUAGEFEATUREHTTPS:GITHUBCOMWYCATSJAVASCRIPTDECORATORSTYPESCRIPTADDSSUPPORTFORDECORATORS", + "original": "A function that modifies the immediately following class or property definition. \nDecorators (also called annotations) are an experimental (stage 2), JavaScript language [feature](https://github.com/wycats/javascript-decorators). \nTypeScript adds support for decorators.", + "translation": "一个函数,用来修饰紧随其后的类或属性定义。\n装饰器(也叫注解)是 JavaScript 的一种语言[特性](https://github.com/wycats/javascript-decorators),是一项位于阶段2(stage 2)的试验特性。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "DECORATORSAREANEXPERIMENTALSTAGE2JAVASCRIPTLANGUAGEFEATUREHTTPS:GITHUBCOMWYCATSJAVASCRIPTDECORATORSTYPESCRIPTADDSSUPPORTFORDECORATORS", - "original": "Decorators are an experimental (stage 2), JavaScript language [feature](https://github.com/wycats/javascript-decorators). TypeScript adds support for decorators.", - "translation": "装饰器是一个 JavaScript 的语言[特性](https://github.com/wycats/javascript-decorators),装饰器在 TypeScript 里已经实现,并被推荐到了 ES2016(也就是 ES7)。", + "key": "ANGULARDEFINESDECORATORSTHATATTACHMETADATATOCLASSESORPROPERTIESSOTHATITKNOWSWHATTHOSECLASSESORPROPERTIESMEANANDHOWTHEYSHOULDWORK", + "original": "Angular defines decorators that attach metadata to classes or properties so that it knows what those classes or properties mean and how they should work.", + "translation": "Angular 定义了一些装饰器,用来为类或属性附加元数据,以便 Angular 了解那些类或属性的含义,以及要如何处理它们。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "TOAPPLYADECORATORPOSITIONITIMMEDIATELYABOVEORTOTHELEFTOFTHEITEMITDECORATES", - "original": "To apply a decorator, position it immediately above or to the left of the item it decorates.", - "translation": "要想应用装饰器,把它放到被装饰对象的上面或左边。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "ANGULARHASITSOWNSETOFDECORATORSTOHELPITINTEROPERATEWITHYOURAPPLICATIONPARTSTHEFOLLOWINGEXAMPLEISACOMPONENTDECORATORTHATIDENTIFIESACLASSASANANGULARCOMPONENTGUIDEGLOSSARY#COMPONENTANDANINPUTDECORATORAPPLIEDTOTHENAMEPROPERTYOFTHATCOMPONENTTHEELIDEDOBJECTARGUMENTTOTHECOMPONENTDECORATORWOULDCONTAINTHEPERTINENTCOMPONENTMETADATA", - "original": "Angular has its own set of decorators to help it interoperate with your application parts.\nThe following example is a `@Component` decorator that identifies a\nclass as an Angular [component](guide/glossary#component) and an `@Input` decorator applied to the `name` property\nof that component. The elided object argument to the `@Component` decorator would contain the pertinent component metadata.", - "translation": "Angular 使用自己的一套装饰器来实现应用程序各部件之间的相互操作。\n下面的例子中使用了 `@Component` 装饰器来将一个类标记为 Angular [组件 (component)](guide/glossary#component),\n并将 `@Input` 装饰器来应用到组件的 `name` 属性。\n`@Component` 装饰器中省略的参数对象会包含与组件有关的元数据。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "THESCOPEOFADECORATORISLIMITEDTOTHELANGUAGEFEATURETHATITDECORATESNONEOFTHEDECORATIONSSHOWNHEREWILLLEAKTOOTHERCLASSESTHATFOLLOWITINTHEFILE", - "original": "The scope of a decorator is limited to the language feature\nthat it decorates. None of the decorations shown here will \"leak\" to other\nclasses that follow it in the file.", - "translation": "装饰器的作用域会被限制在它所装饰的语言特性。\n在同一文件中,装饰器不会“泄露”到它后面的其它类。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "ALWAYSINCLUDEPARENTHESESWHENAPPLYINGADECORATOR", - "original": "Always include parentheses `()` when applying a decorator.", - "translation": "永远别忘了在装饰器后面加括号 `()`。", + "key": "SEECLASSDECORATORGUIDEGLOSSARY#CLASSDECORATORCLASSFIELDDECORATORGUIDEGLOSSARY#CLASSFIELDDECORATOR", + "original": "See [Class decorator](guide/glossary#class-decorator), [Class field decorator](guide/glossary#class-field-decorator).", + "translation": "参见 [类装饰器](guide/glossary#class-decorator)、[类属性装饰器](guide/glossary#class-field-decorator)。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { @@ -13992,81 +14076,33 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "ADESIGNPATTERNANDMECHANISMFORCREATINGANDDELIVERINGPARTSOFANAPPLICATIONTOOTHERPARTSOFANAPPLICATIONTHATREQUESTTHEM", - "original": "A design pattern and mechanism\nfor creating and delivering parts of an application to other\nparts of an application that request them.", - "translation": "依赖注入既是设计模式,同时又是一种机制:当应用程序的一些部件需要另一些部件时,\n利用依赖注入来创建被请求的部件,并将它们注入到发出请求的部件中。", + "key": "ADESIGNPATTERNANDMECHANISMFORCREATINGANDDELIVERINGPARTSOFANAPPLICATIONDEPENDENCIESTOOTHERPARTSOFANAPPLICATIONTHATREQUIRETHEM", + "original": "A design pattern and mechanism for creating and delivering parts of an application (dependencies) to other parts of an application that require them.", + "translation": "依赖注入既是设计模式,同时又是一种机制:当应用程序的一些部件(即一些依赖)需要另一些部件时,\n利用依赖注入来创建被请求的部件,并将它们注入到需要它们的部件中。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "ANGULARDEVELOPERSPREFERTOBUILDAPPLICATIONSBYDEFININGMANYSIMPLEPARTSTHATEACHDOONETHINGWELLANDTHENWIRINGTHEMTOGETHERATRUNTIME", - "original": "Angular developers prefer to build applications by defining many simple parts\nthat each do one thing well and then wiring them together at runtime.", - "translation": "Angular 开发者构建应用程序时的首选方法是:定义许多简单部件,\n每个部件只做一件事并做好它,然后在运行时把它们装配在一起组成应用程序。", + "key": "INANGULARDEPENDENCIESARETYPICALLYSERVICESBUTCANALSOBEVALUESSUCHASSTRINGSORFUNCTIONSANINJECTORGUIDEGLOSSARY#INJECTORFORANAPPCREATEDAUTOMATICALLYDURINGBOOTSTRAPCREATESDEPENDENCIESWHENNEEDEDUSINGAREGISTEREDPROVIDERGUIDEGLOSSARY#PROVIDEROFTHESERVICEORVALUEDIFFERENTPROVIDERSCANPROVIDEDIFFERENTIMPLEMENTATIONSOFTHESAMESERVICE", + "original": "In Angular, dependencies are typically services, but can also be values, such as strings or functions. An [injector](guide/glossary#injector) for an app (created automatically during bootstrap) creates dependencies when needed, using a registered [provider](guide/glossary#provider) of the service or value. Different providers can provide different implementations of the same service.", + "translation": "在 Angular 中,依赖通常是服务,但是也可以是值,比如字符串或函数。应用的[注入器](guide/glossary#injector)(它是在启动期间自动创建的)会使用该服务或值的已注册[提供商](guide/glossary#provider)来按需创建这些依赖。各个不同的提供商可以为同一个服务提供不同的实现。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "THESEPARTSOFTENRELYONOTHERPARTSANANGULARCOMPONENTGUIDEGLOSSARY#COMPONENTPARTMIGHTRELYONASERVICEPARTTOGETDATAORPERFORMACALCULATIONWHENPARTARELIESONANOTHERPARTBYOUSAYTHATADEPENDSONBANDTHATBISADEPENDENCYOFA", - "original": "These parts often rely on other parts. An Angular [component](guide/glossary#component)\npart might rely on a service part to get data or perform a calculation. When\npart \"A\" relies on another part \"B,\" you say that \"A\" depends on \"B\" and\nthat \"B\" is a dependency of \"A.\"", - "translation": "这些部件通常会依赖其它部件。一个 Angular [组件 (component)](guide/glossary#component)\n可能依赖一个服务部件来获取数据或执行运算。\n如果部件 “A” 要靠另一个部件 “B” 才能工作,你就会说 “A” 依赖 “B” ,“B” 是 “A” 的依赖。", + "key": "LEARNMOREINTHEDEPENDENCYINJECTIONGUIDEDEPENDENCYINJECTIONGUIDE", + "original": "Learn more in the [Dependency Injection](guide/dependency-injection) guide.", + "translation": "要了解更多,参见[依赖注入](guide/dependency-injection)一章。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "YOUCANASKADEPENDENCYINJECTIONSYSTEMTOCREATEAFORUSANDHANDLEALLTHEDEPENDENCIESIFANEEDSBANDBNEEDSCTHESYSTEMRESOLVESTHATCHAINOFDEPENDENCIESANDRETURNSAFULLYPREPAREDINSTANCEOFA", - "original": "You can ask a \"dependency injection system\" to create \"A\"\nfor us and handle all the dependencies.\nIf \"A\" needs \"B\" and \"B\" needs \"C,\" the system resolves that chain of dependencies\nand returns a fully prepared instance of \"A.\"", - "translation": "你可以要求“依赖注入系统”创建 “A” 并处理所有依赖。如果 “A” 需要 “B” ,“B” 需要 “C ”,\n系统将解析这个依赖链,返回一个完全准备好的 “A” 实例。", + "key": "##DITOKEN", + "original": "## DI token", + "translation": "## DI 令牌", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "ANGULARPROVIDESANDRELIESUPONITSOWNSOPHISTICATEDDEPENDENCYINJECTIONSYSTEMTOASSEMBLEANDRUNAPPLICATIONSBYINJECTINGAPPLICATIONPARTSINTOOTHERAPPLICATIONPARTSWHEREANDWHENNEEDED", - "original": "Angular provides and relies upon its own sophisticated\ndependency-injection system\nto assemble and run applications by \"injecting\" application parts\ninto other application parts where and when needed.", - "translation": "Angular 提供并使用自己精心设计的[依赖注入 (dependency injection)](guide/dependency-injection)系统来组装和运行应用程序,在需要的地方和时刻,将一些部件“注入”到另一些部件里面。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "ATTHECOREANINJECTORGUIDEGLOSSARY#INJECTORRETURNSDEPENDENCYVALUESONREQUESTTHEEXPRESSIONINJECTORGETTOKENRETURNSTHEVALUEASSOCIATEDWITHTHEGIVENTOKEN", - "original": "At the core, an [`injector`](guide/glossary#injector) returns dependency values on request.\nThe expression `injector.get(token)` returns the value associated with the given token.", - "translation": "在 Angular 内核中有一个[注入器 (injector)](guide/glossary#injector),当请求时返回依赖值。\n表达式 `injector.get(token)` 返回与该 token(令牌)参数相关的值。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "ATOKENISANANGULARTYPEINJECTIONTOKENYOURARELYNEEDTOWORKWITHTOKENSDIRECTLYMOSTMETHODSACCEPTACLASSNAMEFOOORASTRINGFOOANDANGULARCONVERTSITTOATOKENWHENYOUWRITEINJECTORGETFOOTHEINJECTORRETURNSTHEVALUEASSOCIATEDWITHTHETOKENFORTHEFOOCLASSTYPICALLYANINSTANCEOFFOOITSELF", - "original": "A token is an Angular type (`InjectionToken`). You rarely need to work with tokens directly; most\nmethods accept a class name (`Foo`) or a string (\"foo\") and Angular converts it\nto a token. When you write `injector.get(Foo)`, the injector returns\nthe value associated with the token for the `Foo` class, typically an instance of `Foo` itself.", - "translation": "令牌是一个 Angular 中的类型 (`InjectionToken`)。你很少直接处理令牌。\n绝大多数方法都接受类名 (`Foo`) 或字符串 (\"foo\"), Angular 会把这些类名称和字符串转换成令牌。\n当调用 `injector.get(Foo)` 时,注入器返回用 `Foo` 类生成的令牌所对应的依赖值,该依赖值通常是 `Foo` 类的实例。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "DURINGMANYOFITSOPERATIONSANGULARMAKESSIMILARREQUESTSINTERNALLYSUCHASWHENITCREATESACOMPONENTGUIDEGLOSSARY#COMPONENTFORDISPLAY", - "original": "During many of its operations, Angular makes similar requests internally, such as when it creates a [`component`](guide/glossary#component) for display.", - "translation": "Angular 在内部执行很多类似的依赖注入请求,例如,在创建用于显示的[组件 (component)](guide/glossary#component)。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "THEINJECTORMAINTAINSANINTERNALMAPOFTOKENSTODEPENDENCYVALUESIFTHEINJECTORCANTFINDAVALUEFORAGIVENTOKENITCREATESANEWVALUEUSINGAPROVIDERFORTHATTOKEN", - "original": "The `Injector` maintains an internal map of tokens to dependency values.\nIf the `Injector` can't find a value for a given token, it creates\na new value using a `Provider` for that token.", - "translation": "注入器 (`Injector`) 维护一个令牌到依赖值的映射表。\n如果注入器找不到给定令牌对应的依赖值,它会使用提供商 (`Provider`) 创建一个依赖值。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "APROVIDERGUIDEGLOSSARY#PROVIDERISARECIPEFORCREATINGNEWINSTANCESOFADEPENDENCYVALUEASSOCIATEDWITHAPARTICULARTOKEN", - "original": "A [provider](guide/glossary#provider) is a recipe for\ncreating new instances of a dependency value associated with a particular token.", - "translation": "[提供商 (provider)](guide/glossary#provider)是一个“菜谱”,用于创建特定令牌对应的依赖实例。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "ANINJECTORCANONLYCREATEAVALUEFORAGIVENTOKENIFITHASAPROVIDERFORTHATTOKENINITSINTERNALPROVIDERREGISTRYREGISTERINGPROVIDERSISACRITICALPREPARATORYSTEP", - "original": "An injector can only create a value for a given token if it has\na `provider` for that token in its internal provider registry.\nRegistering providers is a critical preparatory step.", - "translation": "只有当注入器内部提供商注册表中存在与令牌对应的提供商时,\n注入器才能为这个令牌创建一个依赖值。所以注册提供商是一个非常关键的准备步骤。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "ANGULARREGISTERSSOMEOFITSOWNPROVIDERSWITHEVERYINJECTORYOUCANREGISTERYOUROWNPROVIDERS", - "original": "Angular registers some of its own providers with every injector.\nYou can register your own providers.", - "translation": "Angular 会为每个注册器注册很多内置提供商。\n你也可以注册自己的提供商。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "READMOREINTHEDEPENDENCYINJECTIONGUIDEDEPENDENCYINJECTIONPAGE", - "original": "Read more in the [Dependency Injection](guide/dependency-injection) page.", - "translation": "更多信息,参见[依赖注入 (dependency injection)](guide/dependency-injection)。", + "key": "ALOOKUPTOKENASSOCIATEDWITHADEPENDENCYPROVIDERGUIDEGLOSSARY#PROVIDERFORUSEWITHTHEDEPENDENCYINJECTIONGUIDEGLOSSARY#DISYSTEM", + "original": "A lookup token associated with a dependency [provider](guide/glossary#provider), for use with the [dependency injection](guide/glossary#di) system.", + "translation": "一种用来查阅的令牌,它关联到一个依赖[提供商](guide/glossary#provider),用于[依赖注入](guide/glossary#di)系统中。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { @@ -14076,51 +14112,81 @@ "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "ANANGULARCLASSRESPONSIBLEFORCREATINGRESHAPINGANDINTERACTINGWITHHTMLELEMENTSINTHEBROWSERDOMTHEDIRECTIVEISANGULARSMOSTFUNDAMENTALFEATURE", - "original": "An Angular class responsible for creating, reshaping, and interacting with HTML elements\nin the browser DOM. The directive is Angular's most fundamental feature.", - "translation": "指令是一个 Angular 类,负责创建和重塑浏览器 DOM 中的 HTML 元素,并与之互动。\n指令是 Angular 中最基本的特性之一。", + "key": "ACLASSWITHTHEDIRECTIVEDECORATORGUIDEGLOSSARY#DECORATORTHATCANMODIFYTHESTRUCTUREOFTHEDOMORMODIFYATTRIBUTESINTHEDOMANDCOMPONENTDATAMODEL", + "original": "A class with the `@Directive` [decorator](guide/glossary#decorator) that can modify the structure of the DOM, or modify attributes in the DOM and component data model.", + "translation": "一个带有 `@Directive` [装饰器](guide/glossary#decorator)的类,它可以修改 DOM 结构或者修改 DOM 的属性和组件数据模型的属性。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "ADIRECTIVEISUSUALLYASSOCIATEDWITHANHTMLELEMENTORATTRIBUTETHISELEMENTORATTRIBUTEISOFTENREFERREDTOASTHEDIRECTIVEITSELF", - "original": "A directive is usually associated with an HTML element or attribute.\nThis element or attribute is often referred to as the directive itself.", - "translation": "指令几乎总与 HTML 元素或属性 (attribute) 相关。\n通常把这些关联到的 HTML 元素或者属性 (attribute) 当做指令本身。", + "key": "ADIRECTIVECLASSISUSUALLYASSOCIATEDWITHANHTMLELEMENTORATTRIBUTEANDTHATELEMENTORATTRIBUTEISOFTENREFERREDTOASTHEDIRECTIVEITSELFWHENANGULARFINDSADIRECTIVEINANHTMLTEMPLATEGUIDEGLOSSARY#TEMPLATEITCREATESTHEMATCHINGDIRECTIVECLASSINSTANCEANDGIVESTHEINSTANCECONTROLOVERTHATPORTIONOFTHEBROWSERDOM", + "original": "A directive class is usually associated with an HTML element or attribute, and that element or attribute is often referred to as the directive itself. \nWhen Angular finds a directive in an HTML [template](guide/glossary#template), it creates the matching directive class instance and gives the instance control over that portion of the browser DOM.", + "translation": "指令类几乎总与 HTML 元素或属性 (attribute) 相关。\n通常会把这些 HTML 元素或者属性 (attribute) 当做指令本身。\n当 Angular 在 HTML [模板中](guide/glossary#template)发现某个指令时,会创建与之相匹配的指令类的实例,并且把这部分 DOM 的控制权交给它。", "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" }, { - "key": "WHENANGULARFINDSADIRECTIVEINANHTMLTEMPLATEITCREATESTHEMATCHINGDIRECTIVECLASSINSTANCEANDGIVESTHEINSTANCECONTROLOVERTHATPORTIONOFTHEBROWSERDOM", - "original": "When Angular finds a directive in an HTML template,\nit creates the matching directive class instance\nand gives the instance control over that portion of the browser DOM.", - "translation": "当 Angular 在 HTML 模板中遇到一个指令的时候,\n它会创建匹配的指令类的实例,并把浏览器中这部分 DOM 的控制权交给它。", - "sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/glossary.md" - }, - { - "key": "YOUCANINVENTCUSTOMHTMLMARKUPFOREXAMPLEMYDIRECTIVETOASSOCIATEWITHYOURCUSTOMDIRECTIVESYOUADDTHISCUSTOMMARKUPTOHTMLTEMPLATESASIFYOUWEREWRITINGNATIVEHTMLINTHISWAYDIRECTIVESBECOMEEXTENSIONSOFHTMLITSELF", - "original": "You can invent custom HTML markup (for example, `