diff --git a/aio/content/marketing/docs.md b/aio/content/marketing/docs.md index d4e976f8fc..d2270e627e 100644 --- a/aio/content/marketing/docs.md +++ b/aio/content/marketing/docs.md @@ -65,7 +65,7 @@ Most Angular code can be written with just the latest JavaScript, using [types]( 有些企业内部的防火墙比较严格,如果无法打开 ,你可以在企业内部进行私有化部署。步骤如下: -本文档的预编译版本位于 [Github](https://github.com/ng-docs/ng-docs.github.io) 上,如果你想进行私有化部署,请把它 Clone 下来,在 nginx 等服务器上按照静态网站的形式做部署即可,除此之外不需要任何服务端环境。 +本文档的预编译版本位于 [Github](https://github.com/ng-docs/latest.angular.live) 上,如果你想进行私有化部署,请把它 Clone 下来,在 nginx 等服务器上按照静态网站的形式做部署即可,除此之外不需要任何服务端环境。 以 Nginx 为例,你需要在 nginx 上做如下改动: diff --git a/packages/animations/src/animation_builder.ts b/packages/animations/src/animation_builder.ts index 9e4435ec64..a3956387e3 100644 --- a/packages/animations/src/animation_builder.ts +++ b/packages/animations/src/animation_builder.ts @@ -13,23 +13,37 @@ import {AnimationPlayer} from './players/animation_player'; * Angular component or directive. * Provided by the `BrowserAnimationsModule` or `NoopAnimationsModule`. * + * 一种可注入服务,可在 Angular 组件或指令中以编程的方式生成动画序列。由 `BrowserAnimationsModule` 或 `NoopAnimationsModule` 提供。 + * * @usageNotes * * To use this service, add it to your component or directive as a dependency. * The service is instantiated along with your component. * + * 要使用此服务,请将其作为依赖项添加到你的组件或指令中。该服务与你的组件一起实例化。 + * * Apps do not typically need to create their own animation players, but if you * do need to, follow these steps: * + * 应用通常不需要创建自己的动画播放器,但是如果需要,请按照以下步骤操作: + * * 1. Use the `build()` method to create a programmatic animation using the * `animate()` function. The method returns an `AnimationFactory` instance. * + * 使用 `build()` 方法创建一个用 `animate()` 函数创建的程序性动画。该方法返回一个 `AnimationFactory` 实例。 + * * 2. Use the factory object to create an `AnimationPlayer` and attach it to a DOM element. * + * 使用工厂对象创建 `AnimationPlayer` 并将其附加到 DOM 元素。 + * * 3. Use the player object to control the animation programmatically. * + * 使用播放器对象以编程方式控制动画。 + * * For example: * + * 例如: + * * ```ts * // import the service from BrowserAnimationsModule * import {AnimationBuilder} from '@angular/animations'; @@ -57,8 +71,17 @@ import {AnimationPlayer} from './players/animation_player'; export abstract class AnimationBuilder { /** * Builds a factory for producing a defined animation. + * + * 建立一个工厂来产生所定义的动画。 + * * @param animation A reusable animation definition. + * + * 可复用的动画定义。 + * * @returns A factory object that can create a player for the defined animation. + * + * 可以为所定义的动画创建播放器的工厂对象。 + * * @see `animate()` */ abstract build(animation: AnimationMetadata|AnimationMetadata[]): AnimationFactory; @@ -67,6 +90,8 @@ export abstract class AnimationBuilder { /** * A factory object returned from the `AnimationBuilder`.`build()` method. * + * 从 `AnimationBuilder`.`build()` 方法返回的工厂对象。。 + * * @publicApi */ export abstract class AnimationFactory { @@ -74,9 +99,18 @@ export abstract class AnimationFactory { * Creates an `AnimationPlayer` instance for the reusable animation defined by * the `AnimationBuilder`.`build()` method that created this factory. * Attaches the new player a DOM element. + * + * 创建一个 `AnimationPlayer` 实例,是由 `AnimationBuilder`.`build()` 方法定义的可复用动画。把这个新的播放器实例附加到一个 DOM 元素上。 + * * @param element The DOM element to which to attach the animation. + * + * 要将动画附加到的 DOM 元素。 + * * @param options A set of options that can include a time delay and * additional developer-defined parameters. + * + * 一组选项,可以包括延迟时间和其他由开发人员定义的参数。 + * */ abstract create(element: any, options?: AnimationOptions): AnimationPlayer; } diff --git a/packages/animations/src/animation_event.ts b/packages/animations/src/animation_event.ts index c377dada56..98aff68d97 100644 --- a/packages/animations/src/animation_event.ts +++ b/packages/animations/src/animation_event.ts @@ -10,6 +10,8 @@ * An instance of this class is returned as an event parameter when an animation * callback is captured for an animation either during the start or done phase. * + * 在开始或完成阶段调用已捕获动画的回调时,将此类的实例作为事件参数返回。 + * * ```typescript * @Component({ * host: { @@ -40,31 +42,52 @@ export interface AnimationEvent { /** * The name of the state from which the animation is triggered. + * + * 触发动画的状态的名称。 + * */ fromState: string; /** * The name of the state in which the animation completes. + * + * 动画完成状态的名称。 + * */ toState: string; /** * The time it takes the animation to complete, in milliseconds. + * + * 动画完成所花费的时间(以毫秒为单位)。 + * */ totalTime: number; /** * The animation phase in which the callback was invoked, one of * "start" or "done". + * + * 调用此回调的动画阶段,是 "start" 或 "done" 之一。 + * */ phaseName: string; /** * The element to which the animation is attached. + * + * 动画附加到的元素。 + * */ element: any; /** * Internal. + * + * 内部。 + * */ triggerName: string; /** * Internal. + * + * 内部。 + * */ disabled: boolean; } diff --git a/packages/animations/src/animation_metadata.ts b/packages/animations/src/animation_metadata.ts index 4af86f41a3..a25270f6fe 100755 --- a/packages/animations/src/animation_metadata.ts +++ b/packages/animations/src/animation_metadata.ts @@ -653,6 +653,7 @@ export interface AnimationStaggerMetadata extends AnimationMetadata { * 用于包装该触发器数据的对象。 * * @usageNotes + * * Define an animation trigger in the `animations` section of `@Component` metadata. * In the template, reference the trigger by name and bind it to a trigger expression that * evaluates to a defined animation state, using the following format: @@ -888,6 +889,7 @@ export function trigger(name: string, definitions: AnimationMetadata[]): Animati * 一个用于封装动画步骤的对象。 * * @usageNotes + * * Call within an animation `sequence()`, `{@link animations/group group()}`, or * `transition()` call to specify an animation step * that applies given style data to the parent animation for a given amount of time. @@ -1002,6 +1004,7 @@ export function animate( * 一个封装了该组数据的对象。 * * @usageNotes + * * Grouped animations are useful when a series of styles must be * animated at different starting times and closed off at different ending times. * @@ -1056,6 +1059,7 @@ export function group( * 一个封装了该动画序列数据的对象。 * * @usageNotes + * * When you pass an array of steps to a * `transition()` call, the steps run sequentially by default. * Compare this to the `{@link animations/group group()}` call, which runs animation steps in @@ -1070,6 +1074,7 @@ export function group( * * 当在 `{@link animations/group group()}` 或 `transition()` 调用中应用动画序列时, * 只有当每个内部动画步骤都完成之后,才会继续执行下一个指令。 + * * @publicApi **/ export function sequence( @@ -1113,6 +1118,7 @@ export function sequence( * 一个封装了样式数据的对象。 * * @usageNotes + * * The following examples create animation styles that collect a set of * CSS property values: * @@ -1185,6 +1191,7 @@ export function style(tokens: '*'|{[key: string]: string | number}| * 一个封装了新状态数据的对象。 * * @usageNotes + * * Use the `trigger()` function to register states to an animation trigger. * Use the `transition()` function to animate between states. * When a state is active within a component, its associated styles persist on the element, @@ -1220,6 +1227,7 @@ export function state( * 一个封装关键帧数据的对象。 * * @usageNotes + * * Use with the `animate()` call. Instead of applying animations * from the current state * to the destination state, keyframes describe how each style entry is applied and at what point @@ -1335,6 +1343,7 @@ export function keyframes(steps: AnimationStyleMetadata[]): AnimationKeyframesSe * 一个封装了转场数据的对象。 * * @usageNotes + * * The template associated with a component binds an animation trigger to an element. * * 与组件关联的模板会把动画触发器绑定到某个元素上。 @@ -1542,6 +1551,7 @@ export function transition( * 一个封装了动画数据的对象。 * * @usageNotes + * * The following example defines a reusable animation, providing some default parameter * values. * @@ -1602,6 +1612,7 @@ export function animation( * 一个对象,封装了子动画数据。 * * @usageNotes + * * Each time an animation is triggered in Angular, the parent animation * has priority and any child animations are blocked. In order * for a child animation to run, the parent animation must query each of the elements @@ -1698,6 +1709,7 @@ export function useAnimation( * 一个封装了查询数据的对象。 * * @usageNotes + * * Tokens can be merged into a combined query selector string. For example: * * 多个令牌可以合并成复合查询选择器。比如: @@ -1774,7 +1786,6 @@ export function useAnimation( * } * } * ``` - * * @publicApi */ export function query( @@ -1802,6 +1813,7 @@ export function query( * 一个封装了交错数据的对象。 * * @usageNotes + * * In the following example, a container element wraps a list of items stamped out * by an `ngFor`. The container element contains an animation trigger that will later be set * to query for each of the inner items. diff --git a/packages/animations/src/players/animation_player.ts b/packages/animations/src/players/animation_player.ts index 3d3472c0c4..fb910f6488 100644 --- a/packages/animations/src/players/animation_player.ts +++ b/packages/animations/src/players/animation_player.ts @@ -12,6 +12,8 @@ import {scheduleMicroTask} from '../util'; * built using the `build()` method of `AnimationBuilder`. The `build()` method * returns a factory, whose `create()` method instantiates and initializes this interface. * + * 提供对可复用动画序列的编程控制,该动画序列是使用 `AnimationBuilder` 的 `build()` 方法构建的。 `build()` 方法返回一个工厂,其 `create()` 方法将实例化并初始化此接口。 + * * @see `AnimationBuilder` * @see `AnimationFactory` * @see `animate()` @@ -21,77 +23,143 @@ import {scheduleMicroTask} from '../util'; export interface AnimationPlayer { /** * Provides a callback to invoke when the animation finishes. + * + * 提供当动画结束时要调用的回调。 + * * @param fn The callback function. + * + * 回调函数。 + * * @see `finish()` */ onDone(fn: () => void): void; /** * Provides a callback to invoke when the animation starts. + * + * 提供当动画启动时要调用的回调。 + * * @param fn The callback function. + * + * 回调函数。 + * * @see `run()` */ onStart(fn: () => void): void; /** * Provides a callback to invoke after the animation is destroyed. + * + * 提供当动画销毁后要调用的回调。 + * * @param fn The callback function. + * + * 回调函数。 + * * @see `destroy()` * @see `beforeDestroy()` */ onDestroy(fn: () => void): void; /** * Initializes the animation. + * + * 初始化本动画。 + * */ init(): void; /** * Reports whether the animation has started. + * + * 报告动画是否已开始。 + * * @returns True if the animation has started, false otherwise. + * + * 如果动画已开始,则为 true,否则为 false。 + * */ hasStarted(): boolean; /** * Runs the animation, invoking the `onStart()` callback. + * + * 运行动画,并调用 `onStart()` 回调。 + * */ play(): void; /** * Pauses the animation. + * + * 暂停动画。 + * */ pause(): void; /** * Restarts the paused animation. + * + * 重新开始已暂停的动画。 + * */ restart(): void; /** * Ends the animation, invoking the `onDone()` callback. + * + * 结束动画,并调用 `onDone()` 回调。 + * */ finish(): void; /** * Destroys the animation, after invoking the `beforeDestroy()` callback. * Calls the `onDestroy()` callback when destruction is completed. + * + * 在调用 `beforeDestroy()` 回调后销毁动画。销毁完成时调用 `onDestroy()`。 + * */ destroy(): void; /** * Resets the animation to its initial state. + * + * 将动画重置为其初始状态。 + * */ reset(): void; /** * Sets the position of the animation. + * + * 设置动画的位置。 + * * @param position A 0-based offset into the duration, in milliseconds. + * + * 持续时间中从 0 开始的偏移量,以毫秒为单位。 + * */ setPosition(position: any /** TODO #9100 */): void; /** * Reports the current position of the animation. + * + * 报告动画的当前位置。 + * * @returns A 0-based offset into the duration, in milliseconds. + * + * 持续时间中从 0 开始的偏移量,以毫秒为单位。 + * */ getPosition(): number; /** * The parent of this player, if any. + * + * 此播放器的父项(如果有)。 + * */ parentPlayer: AnimationPlayer|null; /** * The total run time of the animation, in milliseconds. + * + * 动画的总运行时间(以毫秒为单位)。 + * */ readonly totalTime: number; /** * Provides a callback to invoke before the animation is destroyed. + * + * 提供在动画销毁之前要调用的回调。 + * */ beforeDestroy?: () => any; /** @@ -111,6 +179,8 @@ export interface AnimationPlayer { * Used internally when animations are disabled, to avoid * checking for the null case when an animation player is expected. * + * 用于可复用动画的空白程序控制器。当禁用动画时在内部使用,以免在要用动画播放器时检查其是否为 null。 + * * @see `animate()` * @see `AnimationPlayer` * @see `GroupPlayer` diff --git a/packages/common/http/src/client.ts b/packages/common/http/src/client.ts index 29bf07935e..ed4d059d2b 100644 --- a/packages/common/http/src/client.ts +++ b/packages/common/http/src/client.ts @@ -56,17 +56,25 @@ export type HttpObserve = 'body'|'events'|'response'; * Each request method has multiple signatures, and the return type varies based on * the signature that is called (mainly the values of `observe` and `responseType`). * + * 执行 HTTP 请求。该服务作为可注入类提供,带有执行 HTTP 请求的方法。每个请求方法都有多个签名,并且返回类型会根据所调用的签名(主要的值是 `observe` 和 `responseType`)而有所不同。 + * * Note that the `responseType` *options* value is a String that identifies the * single data type of the response. * A single overload version of the method handles each response type. * The value of `responseType` cannot be a union, as the combined signature could imply. - + * + * 请注意, `responseType` *选项*的值是一个字符串,用于标识此响应的单一数据类型。该方法的各个重载版本处理每种响应类型。正如组合签名所暗示的那样 `responseType` 的值不能为联合类型。 * * @usageNotes + * * Sample HTTP requests for the [Tour of Heroes](/tutorial/toh-pt0) application. * + * [“英雄之旅”](/tutorial/toh-pt0)应用程序的示例 HTTP 请求。 + * * ### HTTP Request Example * + * ### HTTP 请求示例 + * * ``` * // GET heroes whose name contains search term * searchHeroes(term: string): observable{ @@ -75,7 +83,11 @@ export type HttpObserve = 'body'|'events'|'response'; * return this.httpClient.request('GET', this.heroesUrl, {responseType:'json', params}); * } * ``` + * * ### JSONP Example + * + * ### JSONP 示例 + * * ``` * requestJsonp(url, callback = 'callback') { * return this.httpClient.jsonp(this.heroesURL, callback); @@ -83,6 +95,9 @@ export type HttpObserve = 'body'|'events'|'response'; * ``` * * ### PATCH Example + * + * ### PATCH 示例 + * * ``` * // PATCH one of the heroes' name * patchHero (id: number, heroName: string): Observable<{}> { @@ -94,6 +109,8 @@ export type HttpObserve = 'body'|'events'|'response'; * * @see [HTTP Guide](guide/http) * + * [HTTP 指南](guide/http) + * * @publicApi */ @Injectable() @@ -103,7 +120,12 @@ export class HttpClient { /** * Sends an `HTTPRequest` and returns a stream of `HTTPEvents`. * + * 发送 `HTTPRequest` 并返回 `HTTPEvents` 流。 + * * @return An `Observable` of the response, with the response body as a stream of `HTTPEvents`. + * + * 响应对象的 `Observable` ,其响应体为 `HTTPEvents` 流。 + * */ request(req: HttpRequest): Observable>; @@ -111,12 +133,24 @@ export class HttpClient { * Constructs a request that interprets the body as an `ArrayBuffer` and returns the response in * an `ArrayBuffer`. * + * 构造一个请求,它将请求体解释为 `ArrayBuffer`,并且返回 `ArrayBuffer` 格式的响应体。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 * * @return An `Observable` of the response, with the response body as an `ArrayBuffer`. + * + * 响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ request(method: string, url: string, options: { body?: any, @@ -131,11 +165,24 @@ export class HttpClient { * Constructs a request that interprets the body as a blob and returns * the response as a blob. * + * 构造一个请求,将请求体解释为 `Blob` 类型,其响应体为 `Blob` 类型。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body of type `Blob`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Blob` 类型。 + * */ request(method: string, url: string, options: { body?: any, @@ -150,11 +197,24 @@ export class HttpClient { * Constructs a request that interprets the body as a text string and * returns a string value. * + * 构造一个请求,它将请求体解释为字符串,并且返回一个字符串。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ request(method: string, url: string, options: { body?: any, @@ -169,13 +229,26 @@ export class HttpClient { * Constructs a request that interprets the body as an `ArrayBuffer` and returns the * the full event stream. * + * 构造一个请求,它将请求体解释为 `ArrayBuffer`,并返回完整的事件流。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body as an array of `HTTPEvents` for * the * request. + * + * 一个响应对象的 `Observable`,其响应主体为此请求的 `HTTPEvents` + * */ request(method: string, url: string, options: { body?: any, @@ -189,12 +262,25 @@ export class HttpClient { * Constructs a request that interprets the body as a `Blob` and returns * the full event stream. * + * 构造一个请求,它将请求体解释为 `Blob`,并返回完整的事件流。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of of all `HttpEvents` for the request, * with the response body of type `Blob`. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 `Blob` 类型。 + * */ request(method: string, url: string, options: { body?: any, @@ -208,12 +294,25 @@ export class HttpClient { * Constructs a request which interprets the body as a text string and returns the full event * stream. * + * 构造一个请求,它将请求体解释为文本字符串,并且返回完整的事件流。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of all `HttpEvents` for the reques, * with the response body of type string. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 string 类型。 + * */ request(method: string, url: string, options: { body?: any, @@ -227,12 +326,25 @@ export class HttpClient { * Constructs a request which interprets the body as a JSON object and returns the full event * stream. * + * 构造一个请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 要和此请求一起发送的 HTTP 选项。 + * * @return An `Observable` of all `HttpEvents` for the request, * with the response body of type `Object`. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 `Object` 类型。 + * */ request(method: string, url: string, options: { body?: any, @@ -247,12 +359,25 @@ export class HttpClient { * Constructs a request which interprets the body as a JSON object and returns the full event * stream. * + * 构造一个请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of all `HttpEvents` for the request, * with the response body of type `R`. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 `R` 类型。 + * */ request(method: string, url: string, options: { body?: any, @@ -267,11 +392,24 @@ export class HttpClient { * Constructs a request which interprets the body as an `ArrayBuffer` * and returns the full `HTTPResponse`. * + * 构造一个请求,它将请求体解释为 `ArrayBuffer`,并且返回完整的 `HttpResponse`。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse`, with the response body as an `ArrayBuffer`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ request(method: string, url: string, options: { body?: any, @@ -284,11 +422,24 @@ export class HttpClient { /** * Constructs a request which interprets the body as a `Blob` and returns the full `HTTPResponse`. * + * 构造一个请求,它将请求体解释为 `Blob`,并且返回完整的 `HttpResponse`。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse`, with the response body of type `Blob`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Blob` 类型。 + * */ request(method: string, url: string, options: { body?: any, @@ -302,11 +453,24 @@ export class HttpClient { * Constructs a request which interprets the body as a text stream and returns the full * `HTTPResponse`. * + * 构造一个请求,它将请求体解释为文本流,并且返回完整的 `HttpResponse`。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the HTTP response, with the response body of type string. + * + * 此请求的 `HTTP response` 的 `Observable`,其响应体为 string 类型。 + * */ request(method: string, url: string, options: { body?: any, @@ -320,12 +484,25 @@ export class HttpClient { * Constructs a request which interprets the body as a JSON object and returns the full * `HTTPResponse`. * + * 构造一个请求,它将请求体解释为 JSON 对象,并返回完整 `HTTPResponse`。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the full `HTTPResponse`, * with the response body of type `Object`. + * + * 此请求的完整 `HTTPResponse` 的 `Observable`,其响应体为 `Object` 类型。 + * */ request(method: string, url: string, options: { body?: any, @@ -340,11 +517,24 @@ export class HttpClient { * Constructs a request which interprets the body as a JSON object and returns * the full `HTTPResponse` with the response body in the requested type. * + * 构造一个请求,它将请求体解释为 JSON 对象,并返回带有请求主体类型 `HTTPResponse` + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the full `HTTPResponse`, with the response body of type `R`. + * + * 此请求的完整 `HTTPResponse` 的 `Observable`,其响应体为 `R` 类型。 + * */ request(method: string, url: string, options: { body?: any, @@ -359,11 +549,24 @@ export class HttpClient { * Constructs a request which interprets the body as a JSON object and returns the full * `HTTPResponse` as a JSON object. * + * 构造一个请求,它将请求体解释为 JSON 对象,并返回完整的 `HTTPResponse`。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse`, with the response body of type `Object`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Object` 类型。 + * */ request(method: string, url: string, options?: { body?: any, @@ -379,11 +582,24 @@ export class HttpClient { * Constructs a request which interprets the body as a JSON object * with the response body of the requested type. * + * 构造一个请求,它将请求体解释为 JSON 对象,并返回所请求类型的响应体。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse`, with the response body of type `R`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `R` 类型。 + * */ request(method: string, url: string, options?: { body?: any, @@ -398,11 +614,24 @@ export class HttpClient { /** * Constructs a request where response type and requested observable are not known statically. * + * 构造一个请求,其中的响应类型和所请求的可观察对象都不是静态已知的。 + * * @param method The HTTP method. + * + * HTTP 方法。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the reuested response, wuth body of type `any`. + * + * 所请求的响应对象的 `Observable`,其响应体是 `any` 类型。 + * */ request(method: string, url: string, options?: { body?: any, @@ -419,26 +648,48 @@ export class HttpClient { * fires the request through the chain of registered interceptors and on to the * server. * + * 为任意 HTTP 请求构造一个可观察的对象,该请求在被订阅时将通过已注册的拦截器链触发该请求,然后发送到服务器。 + * * You can pass an `HttpRequest` directly as the only parameter. In this case, * the call returns an observable of the raw `HttpEvent` stream. * + * 你可以直接把 `HttpRequest` 作为唯一参数。在这种情况下,该调用将返回原始 `HttpEvent` 流的可观察值。 + * * Alternatively you can pass an HTTP method as the first parameter, * a URL string as the second, and an options hash containing the request body as the third. * See `addBody()`. In this case, the specified `responseType` and `observe` options determine the * type of returned observable. + * + * 或者,你可以将 HTTP 方法作为第一个参数,将 URL 字符串作为第二个参数,将包含请求正文的选项哈希作为第三个参数。参见 `addBody()`。在这种情况下,指定的 `responseType` 和 `observe` 选项会决定要返回的 observable 类型。 + * * * The `responseType` value determines how a successful response body is parsed. + * + * 此 `responseType` 值确定如何解析成功的响应体。 + * * * If `responseType` is the default `json`, you can pass a type interface for the resulting * object as a type parameter to the call. * + * 如果 `responseType` 是默认的 `json` ,则可以将结果对象的类型接口作为类型参数传递给调用。 + * * The `observe` value determines the return type, according to what you are interested in * observing. + * + * `observe` 值根据你感兴趣的观察值确定其返回类型。 + * * * An `observe` value of events returns an observable of the raw `HttpEvent` stream, including * progress events by default. + * + * 事件的 `observe` 值返回原始 `HttpEvent` 流的可观察值,默认情况下包括进度事件。 + * * * An `observe` value of response returns an observable of `HttpResponse`, * where the `T` parameter depends on the `responseType` and any optionally provided type * parameter. + * + * 响应对象的 `observe` 值返回 `HttpResponse` 的可观察对象,其中 `T` 参数取决于 `responseType` 和所提供的可选类型参数。 + * * * An `observe` value of body returns an observable of `` with the same `T` body type. * + * `observe` 的 body 值会返回与 `T` 的响应体具有相同类型的 `` 型可观察对象。 */ request(first: string|HttpRequest, url?: string, options: { body?: any, @@ -560,10 +811,20 @@ export class HttpClient { * Constructs a `DELETE` request that interprets the body as an `ArrayBuffer` * and returns the response as an `ArrayBuffer`. * + * 构造一个 `DELETE` 请求,它将请求体解释为 `ArrayBuffer`,并且返回 `ArrayBuffer` 格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response body as an `ArrayBuffer`. + * + * 类型为 `ArrayBuffer` 的响应体的 `Observable`。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -578,10 +839,20 @@ export class HttpClient { * Constructs a `DELETE` request that interprets the body as a `Blob` and returns * the response as a `Blob`. * + * 构造一个 `DELETE` 请求,它将请求体解释为 `Blob`,并且返回 `Blob` 格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response body as a `Blob`. + * + * 类型为 `Blob` 的响应体的 `Observable`。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -595,10 +866,20 @@ export class HttpClient { * Constructs a `DELETE` request that interprets the body as a text string and returns * a string. * + * 构造一个 `DELETE` 请求,它将请求体解释为字符串,并且返回一个字符串。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -612,11 +893,21 @@ export class HttpClient { * Constructs a `DELETE` request that interprets the body as an `ArrayBuffer` * and returns the full event stream. * + * 构造一个 `DELETE` 请求,它将请求体解释为 `ArrayBuffer`,并返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of all `HTTPEvents` for the request, * with response body as an `ArrayBuffer`. + * + * 此请求的所有 `HTTPEvents` 的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -629,11 +920,21 @@ export class HttpClient { * Constructs a `DELETE` request that interprets the body as a `Blob` * and returns the full event stream. * + * 构造一个 `DELETE` 请求,它将请求体解释为 `Blob`,并返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of all the `HTTPEvents` for the request, with the response body as a * `Blob`. + * + * 此请求的所有 `HTTPEvents` 的 `Observable`,其响应体为 `Blob` 类型。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -646,11 +947,21 @@ export class HttpClient { * Constructs a `DELETE` request that interprets the body as a text string * and returns the full event stream. * + * 构造一个 `DELETE` 请求,它将请求体解释为文本字符串,并且返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of all `HTTPEvents` for the request, with the response * body of type string. + * + * 表示啥此请求的 `HTTPEvents` 的 `Observable`,响应体为 string 类型。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -663,11 +974,21 @@ export class HttpClient { * Constructs a `DELETE` request that interprets the body as a JSON object * and returns the full event stream. * + * 构造一个 `DELETE` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of all `HTTPEvents` for the request, with response body of * type `Object`. + * + * 表示啥此请求的 `HTTPEvents` 的 `Observable`,响应体为 `Object` 类型。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -681,11 +1002,21 @@ export class HttpClient { * Constructs a `DELETE`request that interprets the body as a JSON object * and returns the full event stream. * + * 构造一个 `DELETE` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of all the `HTTPEvents` for the request, with a response * body in the requested type. + * + * 表示此请求的 `HTTPEvents` 的 `Observable`,响应体为所请求的类型。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -699,10 +1030,20 @@ export class HttpClient { * Constructs a `DELETE` request that interprets the body as an `ArrayBuffer` and returns * the full `HTTPResponse`. * + * 构造一个 `DELETE` 请求,它将请求体解释为 `ArrayBuffer`,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the full `HTTPResponse`, with the response body as an `ArrayBuffer`. + * + * 此请求的完整 `HTTPResponse` 的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -715,10 +1056,20 @@ export class HttpClient { * Constructs a `DELETE` request that interprets the body as a `Blob` and returns the full * `HTTPResponse`. * + * 构造一个 `DELETE` 请求,它将请求体解释为 `Blob`,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse`, with the response body of type `Blob`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Blob` 类型。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -731,10 +1082,20 @@ export class HttpClient { * Constructs a `DELETE` request that interprets the body as a text stream and * returns the full `HTTPResponse`. * + * 构造一个 `DELETE` 请求,它将请求体解释为文本流,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the full `HTTPResponse`, with the response body of type string. + * + * 此请求的完整 `HTTPResponse` 的 `Observable`,其响应体为 string 类型。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -747,11 +1108,20 @@ export class HttpClient { * Constructs a `DELETE` request the interprets the body as a JSON object and returns * the full `HTTPResponse`. * + * 构造一个 `DELETE` 请求,它将请求体解释为 JSON 对象,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse`, with the response body of type `Object`. * + * 此请求的响应对象的 `Observable`,其响应体为 `Object` 类型。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -765,10 +1135,20 @@ export class HttpClient { * Constructs a `DELETE` request that interprets the body as a JSON object * and returns the full `HTTPResponse`. * + * 构造一个 `DELETE` 请求,它将请求体解释为 JSON 对象,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse`, with the response body of the requested type. + * + * 此请求的响应对象的 `Observable`,其响应体为所请求的类型。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -782,10 +1162,20 @@ export class HttpClient { * Constructs a `DELETE` request that interprets the body as a JSON object and * returns the response body as a JSON object. * + * 构造一个 `DELETE` 请求,它将请求体解释为 JSON 对象,并且返回 JSON 对象格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body of type `Object`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Object` 类型。 + * */ delete(url: string, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -800,10 +1190,20 @@ export class HttpClient { * Constructs a DELETE request that interprets the body as a JSON object and returns * the response in a given type. * + * 构造一个 `DELETE` 请求,它将请求体解释为 JSON 对象,并且返回给定类型的响应。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse`, with response body in the requested type. + * + * 此请求的响应对象的 `Observable`,其响应体为所请求的类型。 + * */ delete(url: string, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -819,9 +1219,16 @@ export class HttpClient { * `DELETE` request to execute on the server. See the individual overloads for * details on the return type. * + * 构造一个 Observable,当它被订阅时,会要求服务器执行配置好的 `DELETE` 请求。参见它的各个独立重载形式,以了解其返回值类型。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * */ delete(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -839,10 +1246,20 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as an `ArrayBuffer` and returns the * response in an `ArrayBuffer`. * + * 构造一个 `GET` 请求,它将请求体解释为 `ArrayBuffer`,并且返回 `ArrayBuffer` 格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body as an `ArrayBuffer`. + * + * 响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -856,10 +1273,20 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as a `Blob` * and returns the response as a `Blob`. * + * 构造一个 `GET` 请求,它将请求体解释为 `Blob`,并且返回 `Blob` 格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body as a `Blob`. + * + * 响应对象的 `Observable` ,其响应体为 `Blob` 类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -873,10 +1300,20 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as a text string * and returns the response as a string value. * + * 构造一个 `GET` 请求,它将请求体解释为字符串,并且返回字符串格式的响应。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -890,11 +1327,21 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as an `ArrayBuffer` and returns * the full event stream. * + * 构造一个 `GET` 请求,它将请求体解释为 `ArrayBuffer`,并返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of all `HttpEvents` for the request, with the response * body as an `ArrayBuffer`. + * + * 表示此请求的 `HttpEvents` 的 `Observable`,响应体为 n `ArrayBuffer` 类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -907,10 +1354,20 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as a `Blob` and * returns the full event stream. * + * 构造一个 `GET` 请求,它将请求体解释为 `Blob`,并返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body as a `Blob`. + * + * 响应对象的 `Observable` ,其响应体为 `Blob` 类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -923,10 +1380,20 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as a text string and returns * the full event stream. * + * 构造一个 `GET` 请求,它将请求体解释为文本字符串,并且返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -939,10 +1406,20 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as a JSON object * and returns the full event stream. * + * 构造一个 `GET` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body of type `Object`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Object` 类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -956,10 +1433,20 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as a JSON object and returns the full event * stream. * + * 构造一个 `GET` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with a response body in the requested type. + * + * 响应对象的 `Observable` ,其响应体为所请求的类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -973,11 +1460,21 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as an `ArrayBuffer` and * returns the full `HTTPResponse`. * + * 构造一个 `GET` 请求,它将请求体解释为 `ArrayBuffer`,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse` for the request, * with the response body as an `ArrayBuffer`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -990,11 +1487,21 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as a `Blob` and * returns the full `HTTPResponse`. * + * 构造一个 `GET` 请求,它将请求体解释为 `Blob`,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse` for the request, * with the response body as a `Blob`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Blob` 类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1007,11 +1514,21 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as a text stream and * returns the full `HTTPResponse`. * + * 构造一个 `GET` 请求,它将请求体解释为文本流,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse` for the request, * with the response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1024,11 +1541,21 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as a JSON object and * returns the full `HTTPResponse`. * + * 构造一个 `GET` 请求,它将请求体解释为 JSON 对象,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the full `HttpResponse`, * with the response body of type `Object`. + * + * 此请求的完整 `HttpResponse` 的 `Observable`,其响应体为 `Object` 类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1042,11 +1569,21 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as a JSON object and * returns the full `HTTPResponse`. * + * 构造一个 `GET` 请求,它将请求体解释为 JSON 对象,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the full `HTTPResponse` for the request, * with a response body in the requested type. + * + * 此请求的完整 `HTTPResponse` 的 `Observable`,其响应体为所请求的类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1060,11 +1597,20 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as a JSON object and * returns the response body as a JSON object. * + * 构造一个 `GET` 请求,它将请求体解释为 JSON 对象,并且返回 JSON 对象格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 * * @return An `Observable` of the response body as a JSON object. + * + * 响应体的 `Observable` 作为 JSON 对象。 + * */ get(url: string, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1079,10 +1625,20 @@ export class HttpClient { * Constructs a `GET` request that interprets the body as a JSON object and returns * the response body in a given type. * + * 构造一个 `GET` 请求,它将请求体解释为 JSON 对象,并且返回给定类型的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse`, with a response body in the requested type. + * + * 此请求的响应对象的 `Observable`,其响应体为所请求的类型。 + * */ get(url: string, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1097,6 +1653,9 @@ export class HttpClient { * Constructs an observable that, when subscribed, causes the configured * `GET` request to execute on the server. See the individual overloads for * details on the return type. + * + * 构造一个 Observable,当它被订阅时,会要求服务器执行配置好的 `GET` 请求。参见它的各个独立重载形式,以了解其返回值类型。 + * */ get(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1114,10 +1673,20 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as an `ArrayBuffer` and * returns the response as an `ArrayBuffer`. * + * 构造一个 `HEAD` 请求,它将请求体解释为 `ArrayBuffer`,并且返回 `ArrayBuffer` 格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body as an `ArrayBuffer`. + * + * 响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ head(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1131,10 +1700,20 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as a `Blob` and returns * the response as a `Blob`. * + * 构造一个 `HEAD` 请求,它将请求体解释为 `Blob`,并且返回 `Blob` 格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body as a `Blob`. + * + * 响应对象的 `Observable` ,其响应体为 `Blob` 类型。 + * */ head(url: string, options: { @@ -1149,10 +1728,20 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as a text string and returns the response * as a string value. * + * 构造一个 `HEAD` 请求,它将请求体解释为字符串,并且返回字符串格式的响应。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ head(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1166,11 +1755,21 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as an `ArrayBuffer` * and returns the full event stream. * + * 构造一个 `HEAD` 请求,它把请求体解释为 `ArrayBuffer`,并返回完整事件的流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of tall `HttpEvents` for the request, * with the response body as an `ArrayBuffer`. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ head(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1183,11 +1782,21 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as a `Blob` and * returns the full event stream. * + * 构造一个 `HEAD` 请求,它将请求体解释为 `Blob`,并返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of all `HttpEvents` for the request, * with the response body as a `Blob`. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 `Blob` 类型。 + * */ head(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1200,11 +1809,21 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as a text string * and returns the full event stream. * + * 构造一个 `HEAD` 请求,它将请求体解释为文本字符串,并且返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of all HttpEvents for the request, with the response body of type * string. + * + * 表示啥此请求的 `HttpEvents for the request` 的 `Observable`,响应体为 string 类型。 + * */ head(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1217,11 +1836,21 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as a JSON object * and returns the full HTTP event stream. * + * 构造一个 `HEAD` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of all `HTTPEvents` for the request, with a response body of * type `Object`. + * + * 表示啥此请求的 `HTTPEvents` 的 `Observable`,响应体为 `Object` 类型。 + * */ head(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1235,11 +1864,21 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as a JSON object and * returns the full event stream. * + * 构造一个 `HEAD` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @return An `Observable` of all the `HTTPEvents` for the request * , with a response body in the requested type. * + * 表示此请求的 `HTTPEvents` 的 `Observable`,响应体为所请求的类型。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. + * + * 与请求一起发送的 HTTP 选项。 + * */ head(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1253,11 +1892,21 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as an `ArrayBuffer` * and returns the full HTTP response. * + * 构造一个 `HEAD` 请求,它将请求体解释为 `ArrayBuffer`,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse` for the request, * with the response body as an `ArrayBuffer`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ head(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1270,11 +1919,21 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as a `Blob` and returns * the full `HTTPResponse`. * + * 构造一个 `HEAD` 请求,它将请求体解释为 `Blob`,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse` for the request, * with the response body as a blob. + * + * 此请求的响应对象的 `Observable`,其响应体为 blob 类型。 + * */ head(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1287,11 +1946,21 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as text stream * and returns the full `HTTPResponse`. * + * 构造一个 `HEAD` 请求,它将请求体解释为文本流,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse` for the request, * with the response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ head(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1304,11 +1973,21 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as a JSON object and * returns the full `HTTPResponse`. * + * 构造一个 `HEAD` 请求,它将请求体解释为 JSON 对象,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse` for the request, * with the response body of type `Object`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Object` 类型。 + * */ head(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1322,11 +2001,21 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as a JSON object * and returns the full `HTTPResponse`. * + * 构造一个 `HEAD` 请求,它将请求体解释为 JSON 对象,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse` for the request, * with a responmse body of the requested type. + * + * 此请求的响应对象的 `Observable`,其响应体为所请求的类型。 + * */ head(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1340,10 +2029,20 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as a JSON object and * returns the response body as a JSON object. * + * 构造一个 `HEAD` 请求,它将请求体解释为 JSON 对象,并且返回 JSON 对象格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the response, with the response body as a JSON object. + * + * 响应对象的 `Observable` ,其响应体为 JSON 对象。 + * */ head(url: string, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1358,11 +2057,21 @@ export class HttpClient { * Constructs a `HEAD` request that interprets the body as a JSON object and returns * the response in a given type. * + * 构造一个 `HEAD` 请求,它将请求体解释为 JSON 对象,并且返回给定类型的响应。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options The HTTP options to send with the request. * + * 与请求一起发送的 HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse` for the request, * with a response body of the given type. + * + * 此请求的响应对象的 `Observable`,其响应体为给定的类型。 + * */ head(url: string, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1379,6 +2088,9 @@ export class HttpClient { * meta information about the resource without transferring the * resource itself. See the individual overloads for * details on the return type. + * + * 构造一个 Observable,当它被订阅时,会要求服务器执行配置好的 `HEAD` 请求。`HEAD` 方法会返回该资源的元数据,而不会传输资源本身。参见它的各个独立重载形式,以了解其返回类型。 + * */ head(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1394,24 +2106,46 @@ export class HttpClient { /** * Constructs a `JSONP` request for the given URL and name of the callback parameter. * + * 为给定的 URL 和回调参数的名称构造一个 `JSONP` + * * @param url The resource URL. + * + * 资源 URL。 + * * @param callbackParam The callback function name. * + * 回调函数名称。 + * * @return An `Observable` of the response object, with response body as an object. + * + * 响应对象的 `Observable` ,其响应体为对象类型。 + * */ jsonp(url: string, callbackParam: string): Observable; /** * Constructs a `JSONP` request for the given URL and name of the callback parameter. * + * 为给定的 URL 和回调参数的名称构造一个 `JSONP` + * * @param url The resource URL. + * + * 资源 URL。 + * * @param callbackParam The callback function name. * + * 回调函数名称。 + * * You must install a suitable interceptor, such as one provided by `HttpClientJsonpModule`. * If no such interceptor is reached, * then the `JSONP` request can be rejected by the configured backend. * + * 你必须安装合适的拦截器,例如 `HttpClientJsonpModule` 提供的拦截器。如果未经过此类拦截器,则所配置的后端可以拒绝 `JSONP` + * * @return An `Observable` of the response object, with response body in the requested type. + * + * 响应对象的 `Observable` ,其响应体为所请求的类型。 + * */ jsonp(url: string, callbackParam: string): Observable; @@ -1429,9 +2163,16 @@ export class HttpClient { * You can pass the callback function name as one of the query parameters. * Note that JSONP requests can only be used with `GET` requests. * + * 构造一个 `Observable` ,当订阅该 Observable 时,将通过拦截器管道分派特殊的 `JSONP` 方法。[JSONP 模式](https://en.wikipedia.org/wiki/JSONP) 可绕过某些 API 端点的局限性,这些端点不支持新的方式。更推荐使用 [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) 协议。JSONP 将端点 API 视为 JavaScript 文件,并欺骗浏览器处理请求,即使 API 端点与发出请求的客户端应用不在同一个域(源)上。端点 API 必须支持 JSONP 回调,JSONP 请求才能正常工作。此资源 API 会返回包装在回调函数中的 JSON 响应。你可以将回调函数名称作为查询参数之一传递。请注意,JSONP 请求只能与 `GET` 请求一起使用。 + * * @param url The resource URL. + * + * 资源 URL。 + * * @param callbackParam The callback function name. * + * 回调函数名称。 + * */ jsonp(url: string, callbackParam: string): Observable { return this.request('JSONP', url, { @@ -1445,10 +2186,20 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as an * `ArrayBuffer` and returns the response as an `ArrayBuffer`. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为 `ArrayBuffer`,并且返回 `ArrayBuffer` 格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the response, with the response body as an `ArrayBuffer`. + * + * 响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1462,10 +2213,20 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as a `Blob` and returns * the response as a `Blob`. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为 `Blob`,并且返回 `Blob` 格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the response, with the response body as a `Blob`. + * + * 响应对象的 `Observable` ,其响应体为 `Blob` 类型。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1479,10 +2240,20 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as a text string and * returns a string value. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为字符串,并且返回一个字符串。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the response, with the response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1496,11 +2267,21 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as an `ArrayBuffer` * and returns the full event stream. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为 `ArrayBuffer`,并返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of all `HttpEvents` for the request, * with the response body as an `ArrayBuffer`. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1513,11 +2294,21 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as a `Blob` and * returns the full event stream. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为 `Blob`,并返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of all `HttpEvents` for the request, * with the response body as a `Blob`. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 `Blob` 类型。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1530,11 +2321,21 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as a text string * and returns the full event stream. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为文本字符串,并且返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of all the `HTTPEvents` for the request, * with the response body of type string. + * + * 此请求的 `HTTPEvents` 的 `Observable`,其响应体为 string 类型。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1547,11 +2348,21 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as a JSON object * and returns the full event stream. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of all the `HttpEvents` for the request with the response * body of type `Object`. + * + * 表示啥此请求的 `HttpEvents` 的 `Observable`,响应体为 `Object` 类型。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1565,11 +2376,21 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as a JSON object and * returns the full event stream. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of all the `HttpEvents` for the request, * with a response body in the requested type. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为所请求的类型。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1583,11 +2404,21 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as an `ArrayBuffer` * and returns the full HTTP response. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为 `ArrayBuffer`,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the `HttpResponse` for the request, * with the response body as an `ArrayBuffer`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1600,11 +2431,21 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as a `Blob` * and returns the full `HTTPResponse`. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为 `Blob`,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the `HttpResponse` for the request, * with the response body as a `Blob`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Blob` 类型。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1617,11 +2458,21 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as text stream * and returns the full `HTTPResponse`. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为文本流,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the `HttpResponse` for the request, * with the response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1634,11 +2485,21 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as a JSON object * and returns the full `HTTPResponse`. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为 JSON 对象,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the `HttpResponse` for the request, * with the response body of type `Object`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Object` 类型。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1652,11 +2513,21 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as a JSON object and * returns the full `HTTPResponse`. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为 JSON 对象,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the `HttpResponse` for the request, * with a response body in the requested type. + * + * 此请求的响应对象的 `Observable`,其响应体为所请求的类型。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1670,10 +2541,20 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as a JSON object and returns the * response body as a JSON object. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为 JSON 对象,并且返回 JSON 对象格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the response, with the response body as a JSON object. + * + * 响应对象的 `Observable` ,其响应体为 JSON 对象。 + * */ options(url: string, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1688,10 +2569,20 @@ export class HttpClient { * Constructs an `OPTIONS` request that interprets the body as a JSON object and returns the * response in a given type. * + * 构造一个 `OPTIONS` 请求,它将请求体解释为 JSON 对象,并且返回给定类型的响应。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the `HTTPResponse`, with a response body of the given type. + * + * 此请求的响应对象的 `Observable`,其响应体为给定的类型。 + * */ options(url: string, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1708,6 +2599,9 @@ export class HttpClient { * to determine the supported HTTP methods and other capabilites of an endpoint, * without implying a resource action. See the individual overloads for * details on the return type. + * + * 构造一个 `Observable`,当订阅该 Observable 时,它会让已配置的 `OPTIONS` 请求在服务器上执行。此方法允许客户端确定所支持的 HTTP 方法和端点的其他功能,而无需进行隐式资源操作。有关返回类型的详细信息,请参见各个重载。 + * */ options(url: string, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1724,11 +2618,24 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as an `ArrayBuffer` and returns * the response as an `ArrayBuffer`. * + * 构造一个 `PATCH` 请求,它将请求体解释为 `ArrayBuffer`,并且返回 `ArrayBuffer` 格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the response, with the response body as an `ArrayBuffer`. + * + * 响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ patch(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1742,11 +2649,24 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as a `Blob` and returns the response * as a `Blob`. * + * 构造一个 `PATCH` 请求,它将请求体解释为 `Blob`,并且返回 `Blob` 格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the response, with the response body as a `Blob`. + * + * 响应对象的 `Observable` ,其响应体为 `Blob` 类型。 + * */ patch(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1760,11 +2680,24 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as a text string and * returns the response as a string value. * + * 构造一个 `PATCH` 请求,它将请求体解释为字符串,并且返回字符串格式的响应。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the response, with a response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ patch(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1778,12 +2711,25 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as an `ArrayBuffer` and * returns the the full event stream. * + * 构造一个 `PATCH` 请求,它将请求体解释为 `ArrayBuffer`,并返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of all the `HTTPevents` for the request, * with the response body as an `ArrayBuffer`. + * + * 此请求的 `HTTPevents` 的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ patch(url: string, body: any|null, options: { @@ -1797,12 +2743,25 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as a `Blob` * and returns the full event stream. * + * 构造一个 `PATCH` 请求,它将请求体解释为 `Blob`,并返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of all the `HTTPevents` for the request, with the * response body as `Blob`. + * + * 表示此请求的 `HTTPevents` 的 `Observable`,响应体为 `Blob` 类型。 + * */ patch(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1815,12 +2774,25 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as a text string and * returns the full event stream. * + * 构造一个 `PATCH` 请求,它将请求体解释为文本字符串,并且返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of all the `HTTPevents`for the request, with a * response body of type string. + * + * 表示啥此请求的 `HTTPevents` 的 `Observable`,响应体为 string 类型。 + * */ patch(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1833,12 +2805,25 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as a JSON object * and returns the full event stream. * + * 构造一个 `PATCH` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of all the `HTTPevents` for the request, * with a response body of type `Object`. + * + * 此请求的 `HTTPevents` 的 `Observable`,其响应体为 `Object` 类型。 + * */ patch(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1852,12 +2837,25 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as a JSON object * and returns the full event stream. * + * 构造一个 `PATCH` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of all the `HTTPevents` for the request, * with a response body in the requested type. + * + * 此请求的 `HTTPevents` 的 `Observable`,其响应体为所请求的类型。 + * */ patch(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -1871,12 +2869,25 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as an `ArrayBuffer` * and returns the full `HTTPResponse`. * + * 构造一个 `PATCH` 请求,它将请求体解释为 `ArrayBuffer`,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the `HttpResponse` for the request, * with the response body as an `ArrayBuffer`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ patch(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1889,12 +2900,25 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as a `Blob` and returns the full * `HTTPResponse`. * + * 构造一个 `PATCH` 请求,它将请求体解释为 `Blob`,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the `HttpResponse` for the request, * with the response body as a `Blob`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Blob` 类型。 + * */ patch(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1907,12 +2931,25 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as a text stream and returns the * full `HTTPResponse`. * + * 构造一个 `PATCH` 请求,它将请求体解释为文本流,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the `HttpResponse` for the request, * with a response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ patch(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1925,12 +2962,25 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as a JSON object * and returns the full `HTTPResponse`. * + * 构造一个 `PATCH` 请求,它将请求体解释为 JSON 对象,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the `HttpResponse` for the request, * with a response body in the requested type. + * + * 此请求的响应对象的 `Observable`,其响应体为所请求的类型。 + * */ patch(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1944,12 +2994,25 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as a JSON object * and returns the full `HTTPResponse`. * + * 构造一个 `PATCH` 请求,它将请求体解释为 JSON 对象,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the `HttpResponse` for the request, * with a response body in the given type. + * + * 此请求的响应对象的 `Observable`,其响应体为给定的类型。 + * */ patch(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -1963,11 +3026,24 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as a JSON object and * returns the response body as a JSON object. * + * 构造一个 `PATCH` 请求,它将请求体解释为 JSON 对象,并且返回 JSON 对象格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the response, with the response body as a JSON object. + * + * 响应对象的 `Observable` ,其响应体为 JSON 对象。 + * */ patch(url: string, body: any|null, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -1982,12 +3058,25 @@ export class HttpClient { * Constructs a `PATCH` request that interprets the body as a JSON object * and returns the response in a given type. * + * 构造一个 `PATCH` 请求,它将请求体解释为 JSON 对象,并且返回给定类型的响应。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to edit. + * + * 要编辑的资源。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the `HttpResponse` for the request, * with a response body in the given type. + * + * 此请求的响应对象的 `Observable`,其响应体为给定的类型。 + * */ patch(url: string, body: any|null, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -2002,6 +3091,9 @@ export class HttpClient { * Constructs an observable that, when subscribed, causes the configured * `PATCH` request to execute on the server. See the individual overloads for * details on the return type. + * + * 构造一个 Observable,当它被订阅时,会要求服务器执行配置好的 `PATCH` 请求。参见它的各个独立重载形式,以了解其返回值类型。 + * */ patch(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -2018,11 +3110,24 @@ export class HttpClient { * Constructs a `POST` request that interprets the body as an `ArrayBuffer` and returns * an `ArrayBuffer`. * + * 构造一个 `POST` 请求,它将请求体解释为 `ArrayBuffer`,并且返回 `ArrayBuffer`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options. * + * HTTP 选项。 + * * @return An `Observable` of the response, with the response body as an `ArrayBuffer`. + * + * 响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -2036,11 +3141,24 @@ export class HttpClient { * Constructs a `POST` request that interprets the body as a `Blob` and returns the * response as a `Blob`. * + * 构造一个 `POST` 请求,它将请求体解释为 `Blob`,并且返回 `Blob` 格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the response, with the response body as a `Blob`. + * + * 响应对象的 `Observable` ,其响应体为 `Blob` 类型。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -2054,11 +3172,24 @@ export class HttpClient { * Constructs a `POST` request that interprets the body as a text string and * returns the response as a string value. * + * 构造一个 `POST` 请求,它将请求体解释为字符串,并且返回字符串格式的响应。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the response, with a response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -2072,12 +3203,25 @@ export class HttpClient { * Constructs a `POST` request that interprets the body as an `ArrayBuffer` and * returns the full event stream. * + * 构造一个 `POST` 请求,它将请求体解释为 `ArrayBuffer`,并返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of all `HttpEvents` for the request, * with the response body as an `ArrayBuffer`. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -2090,11 +3234,24 @@ export class HttpClient { * Constructs a `POST` request that interprets the body as a `Blob` * and returns the response in an observable of the full event stream. * + * 构造一个 `POST` 请求,它把请求体解释为 `Blob`,并返回完整事件流的 `Observable`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of all `HttpEvents` for the request, with the response body as `Blob`. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 `Blob` 类型。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -2107,12 +3264,25 @@ export class HttpClient { * Constructs a `POST` request that interprets the body as a text string and returns the full * event stream. * + * 构造一个 `POST` 请求,它将请求体解释为文本字符串,并且返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of all `HttpEvents` for the request, * with a response body of type string. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 string 类型。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -2125,12 +3295,25 @@ export class HttpClient { * Constructs a POST request that interprets the body as a JSON object and returns the full event * stream. * + * 构造一个 `POST` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of all `HttpEvents` for the request, * with a response body of type `Object`. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 `Object` 类型。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -2144,12 +3327,25 @@ export class HttpClient { * Constructs a POST request that interprets the body as a JSON object and returns the full event * stream. * + * 构造一个 `POST` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of all `HttpEvents` for the request, * with a response body in the requested type. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为所请求的类型。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -2163,12 +3359,25 @@ export class HttpClient { * Constructs a POST request that interprets the body as an `ArrayBuffer` * and returns the full `HTTPresponse`. * + * 构造一个 POST 请求,它将请求体解释为 `ArrayBuffer` 类型,并返回完整的 `HTTPresponse` 。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the `HTTPResponse` for the request, with the response body as an * `ArrayBuffer`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -2181,12 +3390,25 @@ export class HttpClient { * Constructs a `POST` request that interprets the body as a `Blob` and returns the full * `HTTPResponse`. * + * 构造一个 `POST` 请求,它将请求体解释为 `Blob`,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the `HTTPResponse` for the request, * with the response body as a `Blob`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Blob` 类型。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -2199,12 +3421,25 @@ export class HttpClient { * Constructs a `POST` request that interprets the body as a text stream and returns * the full `HTTPResponse`. * + * 构造一个 `POST` 请求,它将请求体解释为文本流,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the `HTTPResponse` for the request, * with a response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -2217,12 +3452,25 @@ export class HttpClient { * Constructs a `POST` request that interprets the body as a JSON object * and returns the full `HTTPResponse`. * + * 构造一个 `POST` 请求,它将请求体解释为 JSON 对象,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the `HTTPResponse` for the request, with a response body of type * `Object`. + * + * 表示啥此请求的 `HTTPResponse` 的 `Observable`,响应体为 `Object` 类型。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -2236,13 +3484,25 @@ export class HttpClient { * Constructs a `POST` request that interprets the body as a JSON object and returns the full * `HTTPResponse`. * + * 构造一个 `POST` 请求,它将请求体解释为 JSON 对象,并且返回完整的 `HttpResponse`。 * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the `HTTPResponse` for the request, with a response body in the * requested type. + * + * 表示此请求的 `HTTPResponse` 的 `Observable`,响应体为所请求的类型。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -2256,11 +3516,24 @@ export class HttpClient { * Constructs a `POST` request that interprets the body as a * JSON object and returns the response body as a JSON object. * + * 构造一个 `POST` 请求,它将请求体解释为 JSON 对象,并且返回 JSON 对象格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the response, with the response body as a JSON object. + * + * 响应对象的 `Observable` ,其响应体为 JSON 对象。 + * */ post(url: string, body: any|null, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -2275,12 +3548,25 @@ export class HttpClient { * Constructs a `POST` request that interprets the body as a JSON object * and returns an observable of the response. * + * 构造一个 `POST` 请求,它将请求体解释为 JSON 对象,并且返回响应对象的 `Observable`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The content to replace with. + * + * 要替换的内容。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the `HTTPResponse` for the request, with a response body in the * requested type. + * + * 表示此请求的 `HTTPResponse` 的 `Observable`,响应体为所请求的类型。 + * */ post(url: string, body: any|null, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -2296,6 +3582,9 @@ export class HttpClient { * `POST` request to execute on the server. The server responds with the location of * the replaced resource. See the individual overloads for * details on the return type. + * + * 构造一个 `Observable`,当订阅该 Observable 时,它会让已配置的 `POST` 请求在服务器上执行。。服务器以替换后资源的位置进行响应。有关返回类型的详细信息,请参见各个重载。 + * */ post(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -2312,11 +3601,24 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as an `ArrayBuffer` and returns the * response as an `ArrayBuffer`. * + * 构造一个 `PUT` 请求,它将请求体解释为 `ArrayBuffer`,并且返回 `ArrayBuffer` 格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the response, with the response body as an `ArrayBuffer`. + * + * 响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -2330,11 +3632,24 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as a `Blob` and returns * the response as a `Blob`. * + * 构造一个 `PUT` 请求,它将请求体解释为 `Blob`,并且返回 `Blob` 格式的响应体。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the response, with the response body as a `Blob`. + * + * 响应对象的 `Observable` ,其响应体为 `Blob` 类型。 + * */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -2348,11 +3663,24 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as a text string and * returns the response as a string value. * + * 构造一个 `PUT` 请求,它将请求体解释为字符串,并且返回字符串格式的响应。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the response, with a response body of type string. + * + * 此请求的响应对象的 `Observable`,其响应体为 string 类型。 + * */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -2366,12 +3694,25 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as an `ArrayBuffer` and * returns the full event stream. * + * 构造一个 `PUT` 请求,它将请求体解释为 `ArrayBuffer`,并返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of all `HttpEvents` for the request, * with the response body as an `ArrayBuffer`. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -2384,12 +3725,25 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as a `Blob` and returns the full event * stream. * + * 构造一个 `PUT` 请求,它将请求体解释为 `Blob`,并返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of all `HttpEvents` for the request, * with the response body as a `Blob`. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 `Blob` 类型。 + * */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -2402,12 +3756,25 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as a text string and returns the full event * stream. * + * 构造一个 `PUT` 请求,它将请求体解释为文本字符串,并且返回完整的事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of all HttpEvents for the request, with a response body * of type string. + * + * 表示啥此请求的 `HttpEvents for the request` 的 `Observable`,响应体为 string 类型。 + * */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -2420,12 +3787,25 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as a JSON object and returns the full event * stream. * + * 构造一个 `PUT` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of all `HttpEvents` for the request, with a response body of * type `Object`. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为 `Object` 类型。 + * */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -2439,12 +3819,25 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as a JSON object and returns the * full event stream. * + * 构造一个 `PUT` 请求,它将请求体解释为 JSON 对象,并且返回完整的 HTTP 事件流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of all `HttpEvents` for the request, * with a response body in the requested type. + * + * 此请求的 `HttpEvents` 的 `Observable`,其响应体为所请求的类型。 + * */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'events', @@ -2458,12 +3851,25 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as an * `ArrayBuffer` and returns an observable of the full HTTP response. * + * 构造一个 `PUT` 请求,它将请求体解释为 `ArrayBuffer`,并返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the `HTTPResponse` for the request, with the response body as an * `ArrayBuffer`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `ArrayBuffer` 类型。 + * */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -2476,12 +3882,25 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as a `Blob` and returns the * full HTTP response. * + * 构造一个 `PUT` 请求,它将请求体解释为 `Blob`,并且返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the `HTTPResponse` for the request, * with the response body as a `Blob`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Blob` 类型。 + * */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -2494,12 +3913,25 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as a text stream and returns the * full HTTP response. * + * 构造一个 `PUT` 请求,它将请求体解释为文本流,并返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the `HTTPResponse` for the request, with a response body of type * string. + * + * 表示啥此请求的 `HTTPResponse` 的 `Observable`,响应体为 string 类型。 + * */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -2512,12 +3944,23 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as a JSON object and returns the full HTTP * response. * + * 构造一个 `PUT` 请求,它将请求体解释为 JSON 对象,并返回完整的 `HttpResponse`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 * @return An `Observable` of the `HTTPResponse` for the request, with a response body * of type 'Object`. + * + * 此请求的响应对象的 `Observable`,其响应体为 `Object` 类型。 */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -2531,12 +3974,25 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as an instance of the requested type and * returns the full HTTP response. * + * 构造一个 `PUT` 请求,它将请求体解释为所请求类型的实例,并返回完整的 HTTP 响应对象。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the `HTTPResponse` for the request, * with a response body in the requested type. + * + * 此请求的响应对象的 `Observable`,其响应体为所请求的类型。 + * */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, observe: 'response', @@ -2550,11 +4006,24 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as a JSON object * and returns an observable of JSON object. * + * 构造一个 `PUT` 请求,它将请求体解释为 JSON 对象,并返回 JSON 对象的 `Observable`。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the response as a JSON object. + * + * JSON 格式的响应对象的 `Observable` + * */ put(url: string, body: any|null, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -2569,11 +4038,24 @@ export class HttpClient { * Constructs a `PUT` request that interprets the body as an instance of the requested type * and returns an observable of the requested type. * + * 构造一个 `PUT` 请求,它将请求体解释为所请求类型的实例,并返回所请求类型的响应流。 + * * @param url The endpoint URL. + * + * 端点 URL。 + * * @param body The resources to add/update. + * + * 要添加/更新的资源。 + * * @param options HTTP options * + * HTTP 选项 + * * @return An `Observable` of the requested type. + * + * 所请求类型的 `Observable` + * */ put(url: string, body: any|null, options?: { headers?: HttpHeaders|{[header: string]: string | string[]}, @@ -2589,6 +4071,9 @@ export class HttpClient { * `PUT` request to execute on the server. The `PUT` method replaces an existing resource * with a new set of values. * See the individual overloads for details on the return type. + * + * 构造一个 `Observable`,当订阅该 Observable 时,它会让已配置的 `PUT` 请求在服务器上执行。。 `PUT` 方法用一组新值替换现有资源。有关返回类型的详细信息,请参见各个重载。 + * */ put(url: string, body: any|null, options: { headers?: HttpHeaders|{[header: string]: string | string[]}, diff --git a/packages/common/http/src/headers.ts b/packages/common/http/src/headers.ts index 4f3fa7bf61..324c27d57c 100755 --- a/packages/common/http/src/headers.ts +++ b/packages/common/http/src/headers.ts @@ -53,7 +53,12 @@ export class HttpHeaders { */ private lazyUpdate: Update[]|null = null; - /** Constructs a new HTTP header object with the given values.*/ + /** + * Constructs a new HTTP header object with the given values. + * + * 使用给定的值构造一个新的 HTTP 标头对象。 + * + */ constructor(headers?: string|{[name: string]: string | string[]}) { if (!headers) { @@ -161,7 +166,7 @@ export class HttpHeaders { * * @returns A string of values if the header exists, null otherwise. * - * 如果头存在则返回一个字符串数组,否则返回 null。 + * 如果标头存在则返回一个字符串数组,否则返回 null。 * */ getAll(name: string): string[]|null { @@ -174,10 +179,20 @@ export class HttpHeaders { * Appends a new value to the existing set of values for a header * and returns them in a clone of the original instance. * + * 将新值附加到标头的现有值集中,并在原始实例的克隆中返回它们。 + * * @param name The header name for which to append the values. + * + * 要附加值的标头名称。 + * * @param value The value to append. * + * 要附加的值。 + * * @returns A clone of the HTTP headers object with the value appended to the given header. + * + * HTTP 标头对象的克隆,带有由给定标头追加的值。 + * */ append(name: string, value: string|string[]): HttpHeaders { @@ -188,10 +203,20 @@ export class HttpHeaders { * If the header already exists, its value is replaced with the given value * in the returned object. * + * 设置或修改原始实例的克隆中给定标头的值。如果标题已经存在,则其值将在返回对象中被给定值替换。 + * * @param name The header name. + * + * 标头名称。 + * * @param value The value or values to set or overide for the given header. * + * 要设置或覆盖给定标头的一个或多个值。 + * * @returns A clone of the HTTP headers object with the newly set header value. + * + * HTTP 标头对象的克隆,其中包含新设置的标头值。 + * */ set(name: string, value: string|string[]): HttpHeaders { return this.clone({name, value, op: 's'}); @@ -199,10 +224,20 @@ export class HttpHeaders { /** * Deletes values for a given header in a clone of the original instance. * + * 在原始实例的克隆中删除给定标头的值。 + * * @param name The header name. + * + * 标头名称。 + * * @param value The value or values to delete for the given header. * + * 要删除的给定标头的一个或多个值。 + * * @returns A clone of the HTTP headers object with the given value deleted. + * + * HTTP 标头对象的克隆,其中删除了给定值。 + * */ delete(name: string, value?: string|string[]): HttpHeaders { return this.clone({name, value, op: 'd'}); diff --git a/packages/common/http/src/interceptor.ts b/packages/common/http/src/interceptor.ts index abf2d814ec..e24d8e0a3e 100644 --- a/packages/common/http/src/interceptor.ts +++ b/packages/common/http/src/interceptor.ts @@ -60,10 +60,21 @@ import {HttpEvent} from './response'; export interface HttpInterceptor { /** * Identifies and handles a given HTTP request. + * + * 标识并处理给定的 HTTP 请求。 + * * @param req The outgoing request object to handle. + * + * 要处理的传出请求对象。 + * * @param next The next interceptor in the chain, or the backend * if no interceptors remain in the chain. + * + * 链中的下一个拦截器,如果链中没有拦截器,则为其后端接口。 + * * @returns An observable of the event stream. + * + * 事件流的可观察值。 */ intercept(req: HttpRequest, next: HttpHandler): Observable>; } @@ -86,7 +97,7 @@ export class HttpInterceptorHandler implements HttpHandler { * `HttpInterceptor` objects. * * - * 一个多重提供商(multi-provider)令牌,它代表所有已注册的 `HttpInterceptor` 构成的数组。 + * 一个多重提供者(multi-provider)令牌,它代表所有已注册的 `HttpInterceptor` 构成的数组。 * * @publicApi */ diff --git a/packages/common/http/src/jsonp.ts b/packages/common/http/src/jsonp.ts index aefedf20c0..4499ad8b1c 100644 --- a/packages/common/http/src/jsonp.ts +++ b/packages/common/http/src/jsonp.ts @@ -43,6 +43,9 @@ export abstract class JsonpCallbackContext { /** * Processes an `HttpRequest` with the JSONP method, * by performing JSONP style requests. + * + * 通过执行 JSONP 风格的请求,使用 JSONP 方法处理 `HttpRequest` + * * @see `HttpHandler` * @see `HttpXhrBackend` * @@ -52,6 +55,9 @@ export abstract class JsonpCallbackContext { export class JsonpClientBackend implements HttpBackend { /** * A resolved promise that can be used to schedule microtasks in the event handlers. + * + * 已解决的 Promise 可用于安排事件处理器中的微任务。 + * */ private readonly resolvedPromise = Promise.resolve(); @@ -59,6 +65,9 @@ export class JsonpClientBackend implements HttpBackend { /** * Get the name of the next callback method, by incrementing the global `nextRequestId`. + * + * 通过递增 `nextRequestId`,来获取下一个回调方法的名称。 + * */ private nextCallback(): string { return `ng_jsonp_callback_${nextRequestId++}`; @@ -66,9 +75,17 @@ export class JsonpClientBackend implements HttpBackend { /** * Processes a JSONP request and returns an event stream of the results. + * + * 处理 JSONP 请求并返回结果的事件流。 + * * @param req The request object. + * + * 请求对象。 + * * @returns An observable of the response events. * + * 响应事件的可观察对象。 + * */ handle(req: HttpRequest): Observable> { // Firstly, check both the method and response type. If either doesn't match @@ -227,6 +244,8 @@ export class JsonpClientBackend implements HttpBackend { * Identifies requests with the method JSONP and * shifts them to the `JsonpClientBackend`. * + * 使用 JSONP 方法标识这些请求,并将其转移到 `JsonpClientBackend` 。 + * * @see `HttpInterceptor` * * @publicApi @@ -237,10 +256,21 @@ export class JsonpInterceptor { /** * Identifies and handles a given JSONP request. + * + * 识别并处理给定的 JSONP 请求。 + * * @param req The outgoing request object to handle. + * + * 要处理的传出请求对象。 + * * @param next The next interceptor in the chain, or the backend * if no interceptors remain in the chain. + * + * 链中的下一个拦截器,如果链中没有拦截器,则为其后端接口。 + * * @returns An observable of the event stream. + * + * 事件流的可观察对象。 */ intercept(req: HttpRequest, next: HttpHandler): Observable> { if (req.method === 'JSONP') { diff --git a/packages/common/http/src/params.ts b/packages/common/http/src/params.ts index acbedefb8a..fab5fcb8df 100755 --- a/packages/common/http/src/params.ts +++ b/packages/common/http/src/params.ts @@ -28,6 +28,8 @@ export interface HttpParameterCodec { /** * Provides encoding and decoding of URL parameter and query-string values. * + * 提供 URL 参数和查询字符串值的编码和解码。 + * * Serializes and parses URL parameter keys and values to encode and decode them. * If you pass URL query parameters without encoding, * the query parameters can be misinterpreted at the receiving end. @@ -41,8 +43,17 @@ export interface HttpParameterCodec { export class HttpUrlEncodingCodec implements HttpParameterCodec { /** * Encodes a key name for a URL parameter or query-string. + * + * 编码 URL 参数或查询字符串的键名。 + * * @param key The key name. + * + * 键名。 + * * @returns The encoded key name. + * + * 编码过的键名。 + * */ encodeKey(key: string): string { return standardEncoding(key); @@ -50,8 +61,17 @@ export class HttpUrlEncodingCodec implements HttpParameterCodec { /** * Encodes the value of a URL parameter or query-string. + * + * 对 URL 参数或查询字符串的值进行编码。 + * * @param value The value. + * + * 值。 + * * @returns The encoded value. + * + * 编码过的值。 + * */ encodeValue(value: string): string { return standardEncoding(value); @@ -59,8 +79,17 @@ export class HttpUrlEncodingCodec implements HttpParameterCodec { /** * Decodes an encoded URL parameter or query-string key. + * + * 解码编码的 URL 参数或查询字符串键。 + * * @param key The encoded key name. + * + * 编码过的键名。 + * * @returns The decoded key name. + * + * 解码过的键名。 + * */ decodeKey(key: string): string { return decodeURIComponent(key); @@ -68,8 +97,17 @@ export class HttpUrlEncodingCodec implements HttpParameterCodec { /** * Decodes an encoded URL parameter or query-string value. + * + * 解码编码的 URL 参数或查询字符串值。 + * * @param value The encoded value. + * + * 编码过的值。 + * * @returns The decoded value. + * + * 解码过的值。 + * */ decodeValue(value: string) { return decodeURIComponent(value); @@ -145,7 +183,7 @@ export interface HttpParamsOptions { * An HTTP request/response body that represents serialized parameters, * per the MIME type `application/x-www-form-urlencoded`. * - * HTTP 请求/响应体,用来表示序列化参数,它们的 MIME 类型都是 `application/x-www-form-urlencoded`。 + * HTTP 请求体/响应体,用来表示序列化参数,它们的 MIME 类型都是 `application/x-www-form-urlencoded`。 * * This class is immutable; all mutation operations return a new instance. * @@ -179,9 +217,18 @@ export class HttpParams { /** * Reports whether the body includes one or more values for a given parameter. + * + * 报告主体中是否包含给定参数的一个或多个值。 + * * @param param The parameter name. + * + * 参数名称。 + * * @returns True if the parameter has one or more values, * false if it has no value or is not present. + * + * 如果参数具有一个或多个值,则为 true;如果参数没有值或不存在,则为 false。 + * */ has(param: string): boolean { this.init(); @@ -190,7 +237,13 @@ export class HttpParams { /** * Retrieves the first value for a parameter. + * + * 检索参数的第一个值。 + * * @param param The parameter name. + * + * 参数名称。 + * * @returns The first value of the given parameter, * or `null` if the parameter is not present. * @@ -204,7 +257,13 @@ export class HttpParams { /** * Retrieves all values for a parameter. + * + * 检索某个参数的所有值。 + * * @param param The parameter name. + * + * 参数名称。 + * * @returns All values in a string array, * or `null` if the parameter not present. * @@ -217,7 +276,13 @@ export class HttpParams { /** * Retrieves all the parameters for this body. + * + * 检索此 `body` 的所有参数。 + * * @returns The parameter names in a string array. + * + * 字符串数组中的参数名称。 + * */ keys(): string[] { this.init(); @@ -226,8 +291,17 @@ export class HttpParams { /** * Appends a new value to existing values for a parameter. + * + * 将新值附加到参数的现有值。 + * * @param param The parameter name. + * + * 参数名称。 + * * @param value The new value to add. + * + * 要添加的新值。 + * * @return A new body with the appended value. * * 构造一个新的 `body`,添加一个具有给定参数名的值。 @@ -238,8 +312,17 @@ export class HttpParams { /** * Replaces the value for a parameter. + * + * 替换参数的值。 + * * @param param The parameter name. + * + * 参数名称。 + * * @param value The new value. + * + * 新值。 + * * @return A new body with the new value. * * 构造一个新的 `body`,具有一个给定参数名的新值。 @@ -250,8 +333,17 @@ export class HttpParams { /** * Removes a given value or all values from a parameter. + * + * 从参数中删除给定值或所有值。 + * * @param param The parameter name. + * + * 参数名称。 + * * @param value The value to remove, if provided. + * + * 要删除的值(如果提供)。 + * * @return A new body with the given value removed, or with all values * removed if no value is specified. * diff --git a/packages/common/http/src/response.ts b/packages/common/http/src/response.ts index b4464c1393..c33f214317 100644 --- a/packages/common/http/src/response.ts +++ b/packages/common/http/src/response.ts @@ -19,7 +19,7 @@ export enum HttpEventType { /** * The request was sent out over the wire. * - * 该请求已经在线路上发出了。 + * 该请求已经在路由上发出了。 */ Sent, @@ -62,8 +62,8 @@ export enum HttpEventType { /** * Base interface for progress events. * - * * 进度事件的基础接口。 + * * @publicApi */ export interface HttpProgressEvent { @@ -396,7 +396,6 @@ export class HttpResponse extends HttpResponseBase { * will contain either a wrapped Error object or the error response returned * from the server. * - * * 任何从 `Observable` 响应流中返回的错误都会被包装成 `HttpErrorResponse` 对象,以便在发生错误时,提供关于 HTTP 层状态的额外上下文信息。 * 该错误或者包含一个包装好的错误对象,或者包含一个从服务端返回的错误响应体。 * diff --git a/packages/common/http/src/xhr.ts b/packages/common/http/src/xhr.ts index 2618e8417a..d11eea04e9 100644 --- a/packages/common/http/src/xhr.ts +++ b/packages/common/http/src/xhr.ts @@ -33,6 +33,8 @@ function getResponseUrl(xhr: any): string|null { /** * A wrapper around the `XMLHttpRequest` constructor. * + * `XMLHttpRequest` 构造函数的包装器。 + * * @publicApi */ export abstract class XhrFactory { @@ -63,6 +65,9 @@ interface PartialResponse { /** * Uses `XMLHttpRequest` to send requests to a backend server. + * + * 使用 `XMLHttpRequest` 将请求发送到后端服务器。 + * * @see `HttpHandler` * @see `JsonpClientBackend` * @@ -74,8 +79,17 @@ export class HttpXhrBackend implements HttpBackend { /** * Processes a request and returns a stream of response events. + * + * 处理请求并返回响应事件流。 + * * @param req The request object. + * + * 请求对象。 + * * @returns An observable of the response events. + * + * 响应事件的可观察对象。 + * */ handle(req: HttpRequest): Observable> { // Quick check to give a better error message when a user attempts to use diff --git a/packages/common/http/src/xsrf.ts b/packages/common/http/src/xsrf.ts index ae868547f1..1c45a979e4 100644 --- a/packages/common/http/src/xsrf.ts +++ b/packages/common/http/src/xsrf.ts @@ -21,13 +21,20 @@ export const XSRF_HEADER_NAME = new InjectionToken('XSRF_HEADER_NAME'); /** * Retrieves the current XSRF token to use with the next outgoing request. * + * 检索当前的 XSRF 令牌以用于下一个传出请求。 + * * @publicApi */ export abstract class HttpXsrfTokenExtractor { /** * Get the XSRF token to use with an outgoing request. * + * 获取 XSRF 令牌以用于传出请求。 + * * Will be called for every request, so the token may change between requests. + * + * 在每个请求中都会被调用,因此该令牌可能会在请求之间更改。 + * */ abstract getToken(): string|null; } diff --git a/packages/common/http/testing/src/api.ts b/packages/common/http/testing/src/api.ts index 80a7b4aff4..486cee6c14 100644 --- a/packages/common/http/testing/src/api.ts +++ b/packages/common/http/testing/src/api.ts @@ -13,6 +13,8 @@ import {TestRequest} from './request'; /** * Defines a matcher for requests based on URL, method, or both. * + * 为基于 URL 和/或 method 的请求定义匹配器。 + * * @publicApi */ export interface RequestMatch { @@ -24,11 +26,16 @@ export interface RequestMatch { * Controller to be injected into tests, that allows for mocking and flushing * of requests. * + * 控制器将被注入到测试中,从而可以模拟和刷新请求。 + * * @publicApi */ export abstract class HttpTestingController { /** * Search for requests that match the given parameter, without any expectations. + * + * 搜索与给定参数匹配且不带任何期望语句的请求。 + * */ abstract match(match: string|RequestMatch|((req: HttpRequest) => boolean)): TestRequest[]; @@ -36,8 +43,13 @@ export abstract class HttpTestingController { * Expect that a single request has been made which matches the given URL, and return its * mock. * + * 期望发出一个与给定 URL 匹配的单个请求,然后返回其模拟对象。 + * * If no such request has been made, or more than one such request has been made, fail with an * error message including the given request description, if any. + * + * 如果没有发出这样的请求,或者发出过多个这样的请求,则失败,并显示一条错误消息,其中包括给定请求的描述(如果有)。 + * */ abstract expectOne(url: string, description?: string): TestRequest; @@ -45,8 +57,13 @@ export abstract class HttpTestingController { * Expect that a single request has been made which matches the given parameters, and return * its mock. * + * 期望发出一个与给定参数匹配的单个请求,然后返回其模拟对象。 + * * If no such request has been made, or more than one such request has been made, fail with an * error message including the given request description, if any. + * + * 如果没有发出这样的请求,或者发出过多个这样的请求,则失败,并显示一条错误消息,其中包括给定请求的描述(如果有)。 + * */ abstract expectOne(params: RequestMatch, description?: string): TestRequest; @@ -54,8 +71,13 @@ export abstract class HttpTestingController { * Expect that a single request has been made which matches the given predicate function, and * return its mock. * + * 期望发出一个与给定谓词函数匹配的单个请求,然后返回其模拟对象。 + * * If no such request has been made, or more than one such request has been made, fail with an * error message including the given request description, if any. + * + * 如果没有发出这样的请求,或者发出过多个这样的请求,则失败,并显示一条错误消息,其中包括给定请求的描述(如果有)。 + * */ abstract expectOne(matchFn: ((req: HttpRequest) => boolean), description?: string): TestRequest; @@ -64,8 +86,13 @@ export abstract class HttpTestingController { * Expect that a single request has been made which matches the given condition, and return * its mock. * + * 期望发出一个与给定条件匹配的单个请求,然后返回其模拟对象。 + * * If no such request has been made, or more than one such request has been made, fail with an * error message including the given request description, if any. + * + * 如果没有发出这样的请求,或者发出过多个这样的请求,则失败,并显示一条错误消息,其中包括给定请求的描述(如果有)。 + * */ abstract expectOne( match: string|RequestMatch|((req: HttpRequest) => boolean), @@ -74,32 +101,52 @@ export abstract class HttpTestingController { /** * Expect that no requests have been made which match the given URL. * + * 期望没有发出过与给定 URL 匹配的请求。 + * * If a matching request has been made, fail with an error message including the given request * description, if any. + * + * 如果发出了匹配的请求,则失败并显示一条错误消息,其中包括给定请求的描述(如果有)。 + * */ abstract expectNone(url: string, description?: string): void; /** * Expect that no requests have been made which match the given parameters. * + * 期望没有发出过与给定参数匹配的请求。 + * * If a matching request has been made, fail with an error message including the given request * description, if any. + * + * 如果发出了匹配的请求,则失败并显示一条错误消息,其中包括给定请求的描述(如果有)。 + * */ abstract expectNone(params: RequestMatch, description?: string): void; /** * Expect that no requests have been made which match the given predicate function. * + * 期望没有发出过与给定谓词函数匹配的请求。 + * * If a matching request has been made, fail with an error message including the given request * description, if any. + * + * 如果发出了匹配的请求,则失败并显示一条错误消息,其中包括给定请求的描述(如果有)。 + * */ abstract expectNone(matchFn: ((req: HttpRequest) => boolean), description?: string): void; /** * Expect that no requests have been made which match the given condition. * + * 期望没有发出过与给定条件匹配的请求。 + * * If a matching request has been made, fail with an error message including the given request * description, if any. + * + * 如果发出了匹配的请求,则失败并显示一条错误消息,其中包括给定请求的描述(如果有)。 + * */ abstract expectNone( match: string|RequestMatch|((req: HttpRequest) => boolean), description?: string): void; @@ -107,11 +154,18 @@ export abstract class HttpTestingController { /** * Verify that no unmatched requests are outstanding. * + * 验证没有任何未匹配的请求正在等待。 + * * If any requests are outstanding, fail with an error message indicating which requests were not * handled. * + * 如果有任何未完成的请求,则失败并显示一条错误消息,指出未处理哪些请求。 + * * If `ignoreCancelled` is not set (the default), `verify()` will also fail if cancelled requests * were not explicitly matched. + * + * 如果未设置过 `ignoreCancelled`(默认),且未明确匹配已取消的请求,则 `verify()` 就会失败。 + * */ abstract verify(opts?: {ignoreCancelled?: boolean}): void; } diff --git a/packages/common/http/testing/src/module.ts b/packages/common/http/testing/src/module.ts index f1c76c0cfa..8aced4df25 100644 --- a/packages/common/http/testing/src/module.ts +++ b/packages/common/http/testing/src/module.ts @@ -16,8 +16,12 @@ import {HttpClientTestingBackend} from './backend'; /** * Configures `HttpClientTestingBackend` as the `HttpBackend` used by `HttpClient`. * + * 提供配置 `HttpClientTestingBackend` 作为 `HttpBackend` 所使用 `HttpClient` 。 + * * Inject `HttpTestingController` to expect and flush requests in your tests. * + * 注入 `HttpTestingController` 以期望并刷新测试中的请求。 + * * @publicApi */ @NgModule({ diff --git a/packages/common/http/testing/src/request.ts b/packages/common/http/testing/src/request.ts index bdd9121784..794bf77d76 100644 --- a/packages/common/http/testing/src/request.ts +++ b/packages/common/http/testing/src/request.ts @@ -12,14 +12,21 @@ import {Observer} from 'rxjs'; /** * A mock requests that was received and is ready to be answered. * + * 已收到并准备好进行应答的模拟请求。 + * * This interface allows access to the underlying `HttpRequest`, and allows * responding with `HttpEvent`s or `HttpErrorResponse`s. * + * 此接口允许访问底层 `HttpRequest`,并允许使用 `HttpEvent` 或 `HttpErrorResponse` 进行响应。 + * * @publicApi */ export class TestRequest { /** * Whether the request was cancelled after it was sent. + * + * 请求在发送后是否已被取消。 + * */ get cancelled(): boolean { return this._cancelled; @@ -38,7 +45,11 @@ export class TestRequest { * If the request specifies an expected body type, the body is converted into the requested type. * Otherwise, the body is converted to `JSON` by default. * + * 通过返回 body 以及其他 HTTP 信息(例如响应标头)(如果提供过)来解析请求。如果请求指定了预期的 body 类型,则将 body 转换为所请求的类型。否则,body 在默认情况下转换成 `JSON`。 + * * Both successful and unsuccessful responses can be delivered via `flush()`. + * + * 成功和失败的响应都可以通过 `flush()` 传递。 */ flush( body: ArrayBuffer|Blob|boolean|string|number|Object|(boolean|string|number|Object|null)[]| @@ -78,6 +89,9 @@ export class TestRequest { /** * Resolve the request by returning an `ErrorEvent` (e.g. simulating a network failure). + * + * 通过返回 `ErrorEvent` (例如,模拟网络故障)来解决请求。 + * */ error(error: ErrorEvent, opts: { headers?: HttpHeaders|{[name: string]: string | string[]}, @@ -104,6 +118,9 @@ export class TestRequest { /** * Deliver an arbitrary `HttpEvent` (such as a progress event) on the response stream for this * request. + * + * 在响应流上为此请求传递一个任意的 `HttpEvent` + * */ event(event: HttpEvent): void { if (this.cancelled) { diff --git a/packages/common/src/directives/ng_class.ts b/packages/common/src/directives/ng_class.ts index 4a11352107..f7e76d0a97 100644 --- a/packages/common/src/directives/ng_class.ts +++ b/packages/common/src/directives/ng_class.ts @@ -13,6 +13,7 @@ type NgClassSupportedTypes = string[]|Set|{[klass: string]: any}|null|un * @ngModule CommonModule * * @usageNotes + * * ``` * ... * @@ -129,10 +130,15 @@ export class NgClass implements DoCheck { /** * Applies a collection of CSS classes to the DOM element. * + * 将 CSS 类的集合应用于 DOM 元素。 + * * For argument of type Set and Array CSS class names contained in those collections are always * added. * For argument of type Map CSS class name in the map's key is toggled based on the value (added * for truthy and removed for falsy). + * + * 对于 Set 和 Array 类型的参数,总是添加那些集合中包含的 CSS 类名称。对于 Map 类型的参数,与映射表中的键名对应的 CSS 类名称会根据该值进行切换(为 true 添加,为 falsy 删除)。 + * */ private _applyClasses(rawClassVal: NgClassSupportedTypes) { if (rawClassVal) { @@ -147,6 +153,9 @@ export class NgClass implements DoCheck { /** * Removes a collection of CSS classes from the DOM element. This is mostly useful for cleanup * purposes. + * + * 从 DOM 元素中删除 CSS 类的集合。这主要用于清理目的。 + * */ private _removeClasses(rawClassVal: NgClassSupportedTypes) { if (rawClassVal) { diff --git a/packages/common/src/directives/ng_component_outlet.ts b/packages/common/src/directives/ng_component_outlet.ts index 26eb178c2b..7868e59d1b 100644 --- a/packages/common/src/directives/ng_component_outlet.ts +++ b/packages/common/src/directives/ng_component_outlet.ts @@ -13,32 +13,54 @@ import {ComponentFactoryResolver, ComponentRef, Directive, Injector, Input, NgMo * Instantiates a single {@link Component} type and inserts its Host View into current View. * `NgComponentOutlet` provides a declarative approach for dynamic component creation. * + * 实例化单个 {@link Component} 类型,并将其宿主视图插入当前视图。`NgComponentOutlet` 为动态组件创建提供了一种声明式方法。 + * * `NgComponentOutlet` requires a component type, if a falsy value is set the view will clear and * any existing component will get destroyed. * + * `NgComponentOutlet` 所需的组件类型,如果设置为假值,则视图将被清除并且任何现有组件将被销毁。 + * * @usageNotes * * ### Fine tune control * + * ### 微调控制 + * * You can control the component creation process by using the following optional attributes: * + * 你可以使用以下可选属性来控制组件的创建过程: + * * * `ngComponentOutletInjector`: Optional custom {@link Injector} that will be used as parent for * the Component. Defaults to the injector of the current view container. * + * `ngComponentOutletInjector`:可选的自定义 {@link Injector},将用作此组件的父级。默认为当前视图容器的注入器。 + * * * `ngComponentOutletContent`: Optional list of projectable nodes to insert into the content * section of the component, if exists. * + * `ngComponentOutletContent`:要插入到组件内容部分的可投影节点的可选列表(如果存在)。 + * * * `ngComponentOutletNgModuleFactory`: Optional module factory to allow dynamically loading other * module, then load a component from that module. * + * `ngComponentOutletNgModuleFactory`:可选模块工厂,允许动态加载其他模块,然后从该模块加载组件。 + * * ### Syntax * + * ### 语法 + * * Simple + * + * 简单 + * * ``` * * ``` * * Customized injector/content + * + * 定制的注入器/内容 + * * ``` * @@ -55,6 +80,8 @@ import {ComponentFactoryResolver, ComponentRef, Directive, Injector, Input, NgMo * * ### A simple example * + * ### 一个简单的例子 + * * {@example common/ngComponentOutlet/ts/module.ts region='SimpleExample'} * * A more complete example with additional options: diff --git a/packages/common/src/directives/ng_for_of.ts b/packages/common/src/directives/ng_for_of.ts index 6f11b34445..a35053d9a9 100644 --- a/packages/common/src/directives/ng_for_of.ts +++ b/packages/common/src/directives/ng_for_of.ts @@ -37,14 +37,20 @@ export class NgForOfContext = NgIterable> { * The directive is placed on an element, which becomes the parent * of the cloned templates. * + * 一种[结构型指令](guide/structural-directives),为集合中的每个条目渲染一个模板。如果指令放置在一个元素上,该元素就会成为克隆后的模板的父级。 + * * The `ngForOf` directive is generally used in the * [shorthand form](guide/structural-directives#the-asterisk--prefix) `*ngFor`. * In this form, the template to be rendered for each iteration is the content * of an anchor element containing the directive. * + * `ngForOf` 指令通常在 `*ngFor` 的[简写形式](guide/structural-directives#the-asterisk--prefix)内部使用。在这种形式下,每次迭代要渲染的模板是包含指令的锚点元素的内容。 + * * The following example shows the shorthand syntax with some options, * contained in an `
  • ` element. * + * `
  • ` 元素中包含一些选项的简写语法。 + * * ``` *
  • ...
  • * ``` @@ -54,8 +60,12 @@ export class NgForOfContext = NgIterable> { * The content of the `` element is the `
  • ` element that held the * short-form directive. * + * 简写形式会扩展为使用 `` 元素 `ngForOf` 选择器的长形式。`` 元素的内容是包裹此简写格式指令的 `
  • ` 元素。 + * * Here is the expanded version of the short-form example. * + * 这是简写形式示例的扩展版本。 + * * ``` * *
  • ...
  • @@ -66,6 +76,8 @@ export class NgForOfContext = NgIterable> { * The context for each embedded view is logically merged to the current component * context according to its lexical position. * + * Angular 在编译模板时会自动扩展简写语法。每个嵌入式视图的上下文都会根据其词法位置在逻辑上合并到当前组件上下文。 + * * When using the shorthand syntax, Angular allows only [one structural directive * on an element](guide/structural-directives#one-structural-directive-per-host-element). * If you want to iterate conditionally, for example, @@ -73,16 +85,18 @@ export class NgForOfContext = NgIterable> { * For futher discussion, see * [Structural Directives](guide/structural-directives#one-per-element). * - * `NgForOf` 指令会为可迭代对象中的每一个条目实例化一个模板。实例化时的上下文环境来自其外部环境,它以当前正在迭代的条目作为循环变量。 + * 使用简写语法时,Angular 在[一个元素上只允许有一个结构型指令](guide/structural-directives#one-structural-directive-per-host-element)。例如,如果要根据条件进行迭代,请将 `*ngIf` 放在 `*ngFor` 元素的容器元素上。欲知详情,请参见[《结构型指令》](guide/structural-directives#one-per-element) 。 * * @usageNotes * * ### Local variables * + * ### 局部变量 + * * `NgForOf` provides exported values that can be aliased to local variables. * For example: * - * ### 局部变量 + * `NgForOf` 可以为所提供的导出值指定一个局部变量别名。例如: * * ``` *
  • @@ -96,7 +110,7 @@ export class NgForOfContext = NgIterable> { * * - `$implicit: T`: The value of the individual items in the iterable (`ngForOf`). * - * `$implicit: T`:迭代目标(绑定到`ngForOf`)中每个条目的值。 + * `$implicit: T`:迭代目标(绑定到 `ngForOf`)中每个条目的值。 * * - `ngForOf: NgIterable`: The value of the iterable expression. Useful when the expression is * more complex then a property access, for example when using the async pipe (`userStreams | @@ -180,6 +194,9 @@ export class NgForOfContext = NgIterable> { * 如果给出了 `trackBy`,Angular 就会使用该函数的返回值来跟踪变化。 * * @see [Structural Directives](guide/structural-directives) + * + * [结构型指令](guide/structural-directives) + * * @ngModule CommonModule * @publicApi */ @@ -188,6 +205,9 @@ export class NgForOf = NgIterable> implements DoCh /** * The value of the iterable expression, which can be used as a * [template input variable](guide/structural-directives#template-input-variable). + * + * 可迭代表达式的值,可以将其用作[模板输入变量](guide/structural-directives#template-input-variable)。 + * */ @Input() set ngForOf(ngForOf: U&NgIterable|undefined|null) { @@ -197,19 +217,28 @@ export class NgForOf = NgIterable> implements DoCh /** * A function that defines how to track changes for items in the iterable. * + * 定义如何跟踪可迭代项的更改的函数。 + * * When items are added, moved, or removed in the iterable, * the directive must re-render the appropriate DOM nodes. * To minimize churn in the DOM, only nodes that have changed * are re-rendered. * + * 在迭代器中添加、移动或删除条目时,指令必须重新渲染适当的 DOM 节点。为了最大程度地减少 DOM 中的搅动,仅重新渲染已更改的节点。 + * * By default, the change detector assumes that * the object instance identifies the node in the iterable. * When this function is supplied, the directive uses * the result of calling this function to identify the item node, * rather than the identity of the object itself. * + * 默认情况下,变更检测器假定对象实例标识可迭代对象。提供此函数后,指令将使用调用此函数的结果来标识项节点,而不是对象本身的标识。 + * * The function receives two inputs, * the iteration index and the associated node data. + * + * 该函数接收两个输入,即迭代索引和关联的节点数据。 + * */ @Input() set ngForTrackBy(fn: TrackByFunction) { @@ -240,7 +269,13 @@ export class NgForOf = NgIterable> implements DoCh /** * A reference to the template that is stamped out for each item in the iterable. + * + * 此模板引用用来为 iterable 中的生成每个条目。 + * * @see [template reference variable](guide/template-reference-variables) + * + * [模板引用变量](guide/template-reference-variables) + * */ @Input() set ngForTemplate(value: TemplateRef>) { @@ -254,6 +289,9 @@ export class NgForOf = NgIterable> implements DoCh /** * Applies the changes when needed. + * + * 要按需应用的更改。 + * */ ngDoCheck(): void { if (this._ngForOfDirty) { @@ -326,8 +364,13 @@ export class NgForOf = NgIterable> implements DoCh /** * Asserts the correct type of the context for the template that `NgForOf` will render. * + * 为 `NgForOf` 将要渲染的模板确保正确的上下文类型。 + * * The presence of this method is a signal to the Ivy template type-check compiler that the * `NgForOf` structural directive renders its template with a specific context type. + * + * 此方法的存在向 Ivy 模板类型检查编译器发出信号,即 `NgForOf` 结构型指令使用特定的上下文类型渲染其模板。 + * */ static ngTemplateContextGuard>(dir: NgForOf, ctx: any): ctx is NgForOfContext { diff --git a/packages/common/src/directives/ng_if.ts b/packages/common/src/directives/ng_if.ts index f525a907d6..5c88823f77 100644 --- a/packages/common/src/directives/ng_if.ts +++ b/packages/common/src/directives/ng_if.ts @@ -17,20 +17,28 @@ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef, ɵstri * Angular renders the template provided in an optional `else` clause. The default * template for the `else` clause is blank. * + * 本结构型指令用于根据表达式的值(强转为 boolean)是否为真值,来有条件的包含某个模板。当表达式计算为 true 时,Angular 会渲染 `then` 子句中提供的模板,当为 false 或 null 时则渲染可选的 `else` 子句中的模板。`else` 子句的默认模板是空白模板。 + * * A [shorthand form](guide/structural-directives#the-asterisk--prefix) of the directive, * `*ngIf="condition"`, is generally used, provided * as an attribute of the anchor element for the inserted template. * Angular expands this into a more explicit version, in which the anchor element * is contained in an `` element. * + * 通常使用指令的[简写形式](guide/structural-directives#the-asterisk--prefix) `*ngIf="condition"`,作为插入模板的锚点元素的属性提供。Angular 将其扩展为更明确的版本,其中锚点元素包含在 `` 元素中。 + * * Simple form with shorthand syntax: * + * 具有简写语法的简单形式: + * * ``` *
    Content to render when condition is true.
    * ``` * * Simple form with expanded syntax: * + * 具有扩展语法的简单形式: + * * ``` *
    Content to render when condition is * true.
    @@ -38,6 +46,8 @@ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef, ɵstri * * Form with an "else" block: * + * 带有 “else” 块的格式: + * * ``` *
    Content to render when condition is true.
    * Content to render when condition is false. @@ -45,6 +55,8 @@ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef, ɵstri * * Shorthand form with "then" and "else" blocks: * + * 带 “then” 和 “else” 块的简写形式: + * * ``` *
    * Content to render when condition is true. @@ -53,6 +65,8 @@ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef, ɵstri * * Form with storing the value locally: * + * 本地存储值的形式: + * * ``` *
    {{value}}
    * Content to render when value is null. @@ -64,52 +78,74 @@ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef, ɵstri * as seen in the following example. * The default `else` template is blank. * + * `*ngIf` 指令通常用于根据条件显示内联模板,就像下面的例子展示的一样。默认的 `else` 模板是空白的。 + * * {@example common/ngIf/ts/module.ts region='NgIfSimple'} * * ### Showing an alternative template using `else` * + * ### 使用 `else` 显示替代模板 + * * To display a template when `expression` evaluates to false, use an `else` template * binding as shown in the following example. * The `else` binding points to an `` element labeled `#elseBlock`. * The template can be defined anywhere in the component view, but is typically placed right after * `ngIf` for readability. * + * 要在 `expression` 计算为 false 时显示一个模板,请使用如下所示的 `else` 模板绑定。`else` 绑定指向一个带有 `#elseBlock` 标签的 ``。该模板可以定义在组件视图中的任何地方,但通常放在 `ngIf` 的紧后方,以提高可读性。 + * * {@example common/ngIf/ts/module.ts region='NgIfElse'} * * ### Using an external `then` template * + * ### 使用内部 `then` 模板 + * * In the previous example, the then-clause template is specified inline, as the content of the * tag that contains the `ngIf` directive. You can also specify a template that is defined * externally, by referencing a labeled `` element. When you do this, you can * change which template to use at runtime, as shown in the following example. * + * 在前面的例子中,then 子句的模板是内联的,也就是作为 `ngIf` 指令所在标签的内容。你还可以通过引用一个带标签的 `` 元素来指定一个在外部定义的模板。这样就可以让你在运行时更改模板,就像下面的例子所演示的。 + * * {@example common/ngIf/ts/module.ts region='NgIfThenElse'} * * ### Storing a conditional result in a variable * + * ### 把条件结果保存在变量中 + * * You might want to show a set of properties from the same object. If you are waiting * for asynchronous data, the object can be undefined. * In this case, you can use `ngIf` and store the result of the condition in a local * variable as shown in the the following example. * + * 比如你想显示同一个对象中的一组属性。如果你在等待异步数据,此对象可能是未定义的。这时候,你可以使用 `ngIf`,并且把此条件结果保存在一个局部变量中,如下例所示。 + * * {@example common/ngIf/ts/module.ts region='NgIfAs'} * * This code uses only one `AsyncPipe`, so only one subscription is created. * The conditional statement stores the result of `userStream|async` in the local variable `user`. * You can then bind the local `user` repeatedly. * + * 这段代码只使用了一个 `AsyncPipe`,所以只会创建一个订阅。此条件表达式把 `userStream|async` 的结果保存在局部变量 `user` 中。然后你就可以反复绑定这个局部变量 `user` 了。 + * * The conditional displays the data only if `userStream` returns a value, * so you don't need to use the * safe-navigation-operator (`?.`) * to guard against null values when accessing properties. * You can display an alternative template while waiting for the data. * + * 只有当 `userStream` 返回了值的时候,才会有条件的显示此数据。所以你不用使用安全导航操作符 (`?.`) 来在访问属性时避免空值。你可以在等待数据时显示一个备用模板。 + * * ### Shorthand syntax * + * ### 简写语法 + * * The shorthand syntax `*ngIf` expands into two separate template specifications * for the "then" and "else" clauses. For example, consider the following shorthand statement, * that is meant to show a loading page while waiting for data to be loaded. * + * `*ngIf` 的简写语法会把 "then" 和 "else" 子句分别扩展成两个独立的模板。比如,考虑下列简写语句,它要在等待数据加载期间显示一个加载中页面。 + * * ``` *
    * ... @@ -124,11 +160,15 @@ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef, ɵstri * with the `#loading` label, and the template for the "then" clause * is provided as the content of the anchor element. * + * 你可以看到,"else" 子句引用了带有 `#loading` 标签的 ``,而 "then" 子句的模板是作为宿主元素的内容提供的。 + * * However, when Angular expands the shorthand syntax, it creates * another `` tag, with `ngIf` and `ngIfElse` directives. * The anchor element containing the template for the "then" clause becomes * the content of this unlabeled `` tag. * + * 不过,当 Angular 扩展此简写语法的时候,它创建了另一个带有 `ngIf` 和 `ngIfElse` 指令的 ``。此宿主元素包含的 "then" 子句的模板变成了无标签的 `` 的内容。 + * * ``` * *
    @@ -145,6 +185,7 @@ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef, ɵstri * structural directives. For more on this subject, see * [Structural Directives](https://angular.io/guide/structural-directives#one-per-element). * + * 隐式模板对象的存在,影响了结构型指令的嵌套规则。欲知详情,参见[结构型指令](https://angular.io/guide/structural-directives#one-per-element)。 * @ngModule CommonModule * @publicApi */ @@ -162,6 +203,9 @@ export class NgIf { /** * The Boolean expression to evaluate as the condition for showing a template. + * + * 布尔表达式,将其作为显示模板的条件进行计算。 + * */ @Input() set ngIf(condition: T) { @@ -171,6 +215,9 @@ export class NgIf { /** * A template to show if the condition expression evaluates to true. + * + * 当此条件表达式计算为 true 时要显示的模板。 + * */ @Input() set ngIfThen(templateRef: TemplateRef>|null) { @@ -182,6 +229,9 @@ export class NgIf { /** * A template to show if the condition expression evaluates to false. + * + * 当此条件表达式计算为 false 时要显示的模板。 + * */ @Input() set ngIfElse(templateRef: TemplateRef>|null) { @@ -219,18 +269,28 @@ export class NgIf { /** * Assert the correct type of the expression bound to the `ngIf` input within the template. * + * 为绑定到 `ngIf` 输入属性上的模板确保正确的类型。 + * * The presence of this static field is a signal to the Ivy template type check compiler that * when the `NgIf` structural directive renders its template, the type of the expression bound * to `ngIf` should be narrowed in some way. For `NgIf`, the binding expression itself is used to * narrow its type, which allows the strictNullChecks feature of TypeScript to work with `NgIf`. + * + * 该静态字段的存在向 Ivy 模板类型检查编译器发出信号,即当 `NgIf` 结构化指令渲染其模板时,应以某种方式窄化 `ngIf`。对于 `NgIf`,绑定表达式本身用于窄化其类型,这允许 TypeScript 的 strictNullChecks 功能与 `NgIf` 一起使用。 + * */ static ngTemplateGuard_ngIf: 'binding'; /** * Asserts the correct type of the context for the template that `NgIf` will render. * + * 为 `NgIf` 将要渲染的模板确保正确的上下文类型。 + * * The presence of this method is a signal to the Ivy template type-check compiler that the * `NgIf` structural directive renders its template with a specific context type. + * + * 该方法用于向 Ivy 模板类型检查编译器发出信号,即 `NgIf` 结构化指令会使用特定的上下文类型渲染其模板。 + * */ static ngTemplateContextGuard(dir: NgIf, ctx: any): ctx is NgIfContext> { diff --git a/packages/common/src/directives/ng_plural.ts b/packages/common/src/directives/ng_plural.ts index fbd8244724..86be29f7eb 100644 --- a/packages/common/src/directives/ng_plural.ts +++ b/packages/common/src/directives/ng_plural.ts @@ -17,6 +17,7 @@ import {SwitchView} from './ng_switch'; * @ngModule CommonModule * * @usageNotes + * * ``` * * there is nothing @@ -29,19 +30,33 @@ import {SwitchView} from './ng_switch'; * * Adds / removes DOM sub-trees based on a numeric value. Tailored for pluralization. * + * 根据数字值添加/删除 DOM 子树。为支持复数词量身定制。 + * * Displays DOM sub-trees that match the switch expression value, or failing that, DOM sub-trees * that match the switch expression's pluralization category. * + * 显示与开关表达式值匹配的 DOM 子树,否则显示与开关表达式的复数类别匹配的 DOM 子树。 + * * To use this directive you must provide a container element that sets the `[ngPlural]` attribute * to a switch expression. Inner elements with a `[ngPluralCase]` will display based on their * expression: + * + * 要使用此指令,必须提供一个容器元素,该元素将 `[ngPlural]` 属性设置为 switch 表达式。 `[ngPluralCase]` 内部元素将根据其表达式显示: + * * - if `[ngPluralCase]` is set to a value starting with `=`, it will only display if the value * matches the switch expression exactly, + * + * 如果 `[ngPluralCase]` 设置为以 `=` 开头的值,则仅在该值与 switch 表达式完全匹配时才会显示, + * * - otherwise, the view will be treated as a "category match", and will only display if exact * value matches aren't found and the value maps to its category for the defined locale. * + * 否则,该视图将被视为“类别匹配”,并且仅在未找到精确值匹配且该值映射到已定义语言环境的类别时才会显示。 + * * See http://cldr.unicode.org/index/cldr-spec/plural-rules * + * 参见 + * * @publicApi */ @Directive({selector: '[ngPlural]'}) @@ -92,7 +107,10 @@ export class NgPlural { * Creates a view that will be added/removed from the parent {@link NgPlural} when the * given expression matches the plural expression according to CLDR rules. * + * 创建一个视图,当给定表达式根据 CLDR 规则与复数表达式匹配时,将在父视图 {@link NgPlural} 中添加/删除该视图。 + * * @usageNotes + * * ``` * * ... @@ -102,6 +120,8 @@ export class NgPlural { * * See {@link NgPlural} for more details and example. * + * 参见 {@link NgPlural} 以了解详情和范例。 + * * @publicApi */ @Directive({selector: '[ngPluralCase]'}) diff --git a/packages/common/src/directives/ng_style.ts b/packages/common/src/directives/ng_style.ts index 6c5a77225c..e36415069c 100644 --- a/packages/common/src/directives/ng_style.ts +++ b/packages/common/src/directives/ng_style.ts @@ -15,18 +15,24 @@ import {Directive, DoCheck, ElementRef, Input, KeyValueChanges, KeyValueDiffer, * * Set the font of the containing element to the result of an expression. * + * 将容器元素的字体设置为表达式的结果。 + * * ``` * ... * ``` * * Set the width of the containing element to a pixel value returned by an expression. * + * 将容器元素的宽度设置为表达式返回的像素值。 + * * ``` * ... * ``` * * Set a collection of style values using an expression that returns key-value pairs. * + * 使用返回键值对的表达式来设置样式值的集合。 + * * ``` * ... * ``` diff --git a/packages/common/src/directives/ng_switch.ts b/packages/common/src/directives/ng_switch.ts index 5847340383..6f36836693 100644 --- a/packages/common/src/directives/ng_switch.ts +++ b/packages/common/src/directives/ng_switch.ts @@ -39,15 +39,29 @@ export class SwitchView { * @description * The `[ngSwitch]` directive on a container specifies an expression to match against. * The expressions to match are provided by `ngSwitchCase` directives on views within the container. + * + * 容器上的 `[ngSwitch]` 指令指定要匹配的表达式。匹配的表达式由容器内视图上的 `ngSwitchCase` 指令提供。 + * * - Every view that matches is rendered. + * + * 如果有匹配项,则渲染匹配的视图。 + * * - If there are no matches, a view with the `ngSwitchDefault` directive is rendered. + * + * 如果没有匹配项,则渲染 `ngSwitchDefault` + * * - Elements within the `[NgSwitch]` statement but outside of any `NgSwitchCase` * or `ngSwitchDefault` directive are preserved at the location. * + * `[NgSwitch]` 语句内任何除 `NgSwitchCase` 或 `ngSwitchDefault` 指令之外的元素都保留在原位。 + * * @usageNotes + * * Define a container element for the directive, and specify the switch expression * to match against as an attribute: * + * 为指令定义一个容器元素,并指定要匹配的 switch 表达式作为属性: + * * ``` * * ``` @@ -55,6 +69,8 @@ export class SwitchView { * Within the container, `*ngSwitchCase` statements specify the match expressions * as attributes. Include `*ngSwitchDefault` as the final case. * + * 在容器内, `*ngSwitchCase` 语句将匹配表达式指定为属性。包括用 `*ngSwitchDefault` 作为最后一种情况。 + * * ``` * * ... @@ -65,8 +81,12 @@ export class SwitchView { * * ### Usage Examples * + * ### 使用范例 + * * The following example shows how to use more than one case to display the same view: * + * 下面的示例演示如何使用多个分支来显示同一视图: + * * ``` * * @@ -79,6 +99,9 @@ export class SwitchView { * ``` * * The following example shows how cases can be nested: + * + * 以下示例演示如何嵌套案例: + * * ``` * * ... @@ -98,6 +121,7 @@ export class SwitchView { * @see `NgSwitchDefault` * @see [Structural Directives](guide/structural-directives) * + * [结构型指令](guide/structural-directives) */ @Directive({selector: '[ngSwitch]'}) export class NgSwitch { @@ -162,11 +186,15 @@ export class NgSwitch { * When the expressions match, the given `NgSwitchCase` template is rendered. * If multiple match expressions match the switch expression value, all of them are displayed. * + * 提供一个 switch case 表达式来匹配一个封闭的 `ngSwitch` 表达式。当表达式匹配时,将渲染给定的 `NgSwitchCase` 模板。如果多个匹配表达式与开关表达式值相匹配,则会全部显示。 + * * @usageNotes * * Within a switch container, `*ngSwitchCase` statements specify the match expressions * as attributes. Include `*ngSwitchDefault` as the final case. * + * 在开关容器中, `*ngSwitchCase` 语句将匹配表达式指定为属性。包括用 `*ngSwitchDefault` 作为最后一种情况。 + * * ``` * * ... @@ -179,9 +207,13 @@ export class NgSwitch { * that defines the subtree to be selected if the value of the match expression * matches the value of the switch expression. * + * 每个 switch-case 语句包含一个内联 HTML 模板或模板引用,该模板或模板引用定义了 match 表达式的值与 switch 表达式的值匹配时要选择的子树。 + * * Unlike JavaScript, which uses strict equality, Angular uses loose equality. * This means that the empty string, `""` matches 0. * + * 与 JavaScript 使用严格相等性的方式不同,Angular 使用宽松相等性。这意味着空字符串 `""` 能匹配 0。 + * * @publicApi * @see `NgSwitch` * @see `NgSwitchDefault` @@ -192,6 +224,9 @@ export class NgSwitchCase implements DoCheck { private _view: SwitchView; /** * Stores the HTML template to be selected on match. + * + * 存储要在匹配时选择的 HTML 模板。 + * */ @Input() ngSwitchCase: any; @@ -204,6 +239,9 @@ export class NgSwitchCase implements DoCheck { /** * Performs case matching. For internal use only. + * + * 执行大小写匹配。仅限内部使用。 + * */ ngDoCheck() { this._view.enforceState(this.ngSwitch._matchCase(this.ngSwitchCase)); @@ -219,6 +257,8 @@ export class NgSwitchCase implements DoCheck { * match the `NgSwitch` expression. * This statement should be the final case in an `NgSwitch`. * + * 创建一个当没有任何 `NgSwitchCase` 表达式能匹配 `NgSwitch` 表达时要渲染的视图。该语句应该是 `NgSwitch` 的最后一种情况。 + * * @publicApi * @see `NgSwitch` * @see `NgSwitchCase` diff --git a/packages/common/src/directives/ng_template_outlet.ts b/packages/common/src/directives/ng_template_outlet.ts index 29204e04a1..7bcdb401f2 100644 --- a/packages/common/src/directives/ng_template_outlet.ts +++ b/packages/common/src/directives/ng_template_outlet.ts @@ -51,11 +51,17 @@ export class NgTemplateOutlet implements OnChanges { * object, the object's keys will be available for binding by the local template `let` * declarations. * Using the key `$implicit` in the context object will set its value as default. + * + * 附加到 {@link EmbeddedViewRef} 的上下文对象。这应该是一个对象,该对象的键名将可以在局部模板中使用 `let` 声明中进行绑定。在上下文对象中使用 `$implicit` 为键名时,将把它作为默认值。 + * */ @Input() public ngTemplateOutletContext: Object|null = null; /** * A string defining the template reference and optionally the context object for the template. + * + * 一个字符串,用于定义模板引用以及模板的上下文对象。 + * */ @Input() public ngTemplateOutlet: TemplateRef|null = null; diff --git a/packages/common/src/dom_tokens.ts b/packages/common/src/dom_tokens.ts index e7c8d9fc30..9bd13647a6 100644 --- a/packages/common/src/dom_tokens.ts +++ b/packages/common/src/dom_tokens.ts @@ -11,9 +11,13 @@ import {InjectionToken} from '@angular/core'; /** * A DI Token representing the main rendering context. In a browser this is the DOM Document. * + * 表示主要渲染上下文的 DI 令牌。在浏览器中,这是 DOM 文档。 + * * Note: Document might not be available in the Application Context when Application and Rendering * Contexts are not the same (e.g. when running the application in a Web Worker). * + * 注意:当应用程序上下文和渲染上下文不同时(例如,在 Web Worker 中运行应用程序时),document 可能在应用程序上下文中不可用。 + * * @publicApi */ export const DOCUMENT = new InjectionToken('DocumentToken'); diff --git a/packages/common/src/i18n/format_number.ts b/packages/common/src/i18n/format_number.ts index 62b53361ca..ea6691e6f4 100644 --- a/packages/common/src/i18n/format_number.ts +++ b/packages/common/src/i18n/format_number.ts @@ -128,23 +128,43 @@ function formatNumberToLocaleString( * * Formats a number as currency using locale rules. * + * 使用区域设置规则将数字格式化为货币。 + * * @param value The number to format. + * + * 要格式化的数字。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @param currency A string containing the currency symbol or its name, * such as "$" or "Canadian Dollar". Used in output string, but does not affect the operation * of the function. + * + * 包含货币符号或其名称的字符串,例如 “$” 或 “加元”。在输出字符串中使用,但不影响该函数的操作。 + * * @param currencyCode The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) * currency code, such as `USD` for the US dollar and `EUR` for the euro. * Used to determine the number of digits in the decimal part. + * + * [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) 货币代码,例如 `USD` 表示美元,`EUR` 表示欧元。用于确定小数部分的位数。 + * * @param digitInfo Decimal representation options, specified by a string in the following format: * `{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}`. See `DecimalPipe` for more details. * + * 十进制表示形式的选项,通过字符串以如下格式指定:`{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}` 。欲知详情,请参见 `DecimalPipe`。 + * * @returns The formatted currency value. * + * 要格式化的货币值。 + * * @see `formatNumber()` * @see `DecimalPipe` * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function formatCurrency( @@ -175,16 +195,31 @@ export function formatCurrency( * * Formats a number as a percentage according to locale rules. * + * 根据语言环境规则将数字格式化为百分比。 + * * @param value The number to format. + * + * 要格式化的数字。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @param digitInfo Decimal representation options, specified by a string in the following format: * `{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}`. See `DecimalPipe` for more details. * + * 十进制表示形式的选项,通过字符串以如下格式指定:`{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}`。欲知详情,请参见 `DecimalPipe`。 + * * @returns The formatted percentage value. * + * 已格式化的百分比值。 + * * @see `formatNumber()` * @see `DecimalPipe` * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) + * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi * */ @@ -204,14 +239,29 @@ export function formatPercent(value: number, locale: string, digitsInfo?: string * Formats a number as text, with group sizing, separator, and other * parameters based on the locale. * + * 将数字格式化为文本格式,并根据区域来设置组大小、分隔符和其他参数。 + * * @param value The number to format. + * + * 要格式化的数字。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @param digitInfo Decimal representation options, specified by a string in the following format: * `{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}`. See `DecimalPipe` for more details. * + * 十进制表示形式的选项,通过字符串以如下格式指定:`{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}` 。欲知详情,请参见 `DecimalPipe`。 + * * @returns The formatted text string. + * + * 已格式化的文本字符串。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function formatNumber(value: number, locale: string, digitsInfo?: string): string { diff --git a/packages/common/src/i18n/locale_data.ts b/packages/common/src/i18n/locale_data.ts index ace7b33d0a..44c90219fb 100644 --- a/packages/common/src/i18n/locale_data.ts +++ b/packages/common/src/i18n/locale_data.ts @@ -12,8 +12,12 @@ import {ɵregisterLocaleData} from '@angular/core'; * Register global data to be used internally by Angular. See the * ["I18n guide"](guide/i18n#i18n-pipes) to know how to import additional locale data. * + * 注册全局数据以供 Angular 内部使用。请参阅 [“I18n 指南”](guide/i18n#i18n-pipes)以了解如何导入其他语言环境的数据。 + * * The signature registerLocaleData(data: any, extraData?: any) is deprecated since v5.1 * + * 从 v5.1 开始不推荐使用 registerLocaleData(data:any,extraData ?: any)签名 + * * @publicApi */ export function registerLocaleData(data: any, localeId?: string|any, extraData?: any): void { diff --git a/packages/common/src/i18n/locale_data_api.ts b/packages/common/src/i18n/locale_data_api.ts index 20221f759b..3aa93de47e 100644 --- a/packages/common/src/i18n/locale_data_api.ts +++ b/packages/common/src/i18n/locale_data_api.ts @@ -13,9 +13,15 @@ import {CURRENCIES_EN, CurrenciesSymbols} from './currencies'; /** * Format styles that can be used to represent numbers. + * + * 可用来表示数字的格式化样式。 + * * @see `getLocaleNumberFormat()`. + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export enum NumberFormatStyle { @@ -28,10 +34,15 @@ export enum NumberFormatStyle { /** * Plurality cases used for translating plurals to different languages. * + * 用于将复数形式转换为不同语言的复数形式。 + * * @see `NgPlural` + * * @see `NgPluralCase` * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export enum Plural { @@ -47,9 +58,17 @@ export enum Plural { * Context-dependant translation forms for strings. * Typically the standalone version is for the nominative form of the word, * and the format version is used for the genitive case. + * + * 字符串的上下文相关翻译形式。通常,独立版本用于单词的主格形式,格式化的版本则用于所有格。 + * * @see [CLDR website](http://cldr.unicode.org/translation/date-time-1/date-time#TOC-Standalone-vs.-Format-Styles) + * + * [CLDR 网站](http://cldr.unicode.org/translation/date-time-1/date-time#TOC-Standalone-vs.-Format-Styles) + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export enum FormStyle { @@ -62,16 +81,38 @@ export enum FormStyle { * The specific character widths are locale-specific. * Examples are given for the word "Sunday" in English. * + * 字符串宽度可用于翻译。特定的字符宽度是特定于语言环境的。这里给出了英语中 “Sunday” 一词的示例。 + * * @publicApi */ export enum TranslationWidth { - /** 1 character for `en-US`. For example: 'S' */ + /** + * 1 character for `en-US`. For example: 'S' + * + * 对 `en-US` 是 1 字符。比如:'S' + * + */ Narrow, - /** 3 characters for `en-US`. For example: 'Sun' */ + /** + * 3 characters for `en-US`. For example: 'Sun' + * + * 对 `en-US` 是 3 字符。比如:'Sun' + * + */ Abbreviated, - /** Full length for `en-US`. For example: "Sunday" */ + /** + * Full length for `en-US`. For example: "Sunday" + * + * 对 `en-US` 是全长。例如:“星期日” + * + */ Wide, - /** 2 characters for `en-US`, For example: "Su" */ + /** + * 2 characters for `en-US`, For example: "Su" + * + * 对 `en-US` 是 2 个字符,例如:“Su” + * + */ Short } @@ -80,31 +121,48 @@ export enum TranslationWidth { * The specific character widths are locale-specific. * Examples are given for `en-US`. * + * 可用于日期时间格式的字符串宽度。特定的字符宽度是特定于语言环境的。示例中是给 `en-US` 的示例。 + * * @see `getLocaleDateFormat()` * @see `getLocaleTimeFormat()`` * @see `getLocaleDateTimeFormat()` * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) + * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export enum FormatWidth { /** * For `en-US`, 'M/d/yy, h:mm a'` * (Example: `6/15/15, 9:03 AM`) + * + * 对于 `en-US`,是 'M/d/yy, h:mm a'`(例如:`6/15/15, 9:03 AM`) + * */ Short, /** * For `en-US`, `'MMM d, y, h:mm:ss a'` * (Example: `Jun 15, 2015, 9:03:01 AM`) + * + * 对于 `en-US`,是 `'MMM d, y, h:mm:ss a'`(例如: `Jun 15, 2015, 9:03:01 AM` ) + * */ Medium, /** * For `en-US`, `'MMMM d, y, h:mm:ss a z'` * (Example: `June 15, 2015 at 9:03:01 AM GMT+1`) + * + * 对于 `en-US`,是 `'MMMM d, y, h:mm:ss a z'`,(例如: `June 15, 2015 at 9:03:01 AM GMT+1` ) + * */ Long, /** * For `en-US`, `'EEEE, MMMM d, y, h:mm:ss a zzzz'` * (Example: `Monday, June 15, 2015 at 9:03:01 AM GMT+01:00`) + * + * 对于 `en-US`,是 `'EEEE, MMMM d, y, h:mm:ss a zzzz'`(例如:`Monday, June 15, 2015 at 9:03:01 AM GMT+01:00` ) + * */ Full } @@ -113,9 +171,14 @@ export enum FormatWidth { * Symbols that can be used to replace placeholders in number patterns. * Examples are based on `en-US` values. * + * 可用于替换数字模式中占位符的符号。例如基于 `en-US` 的值。 + * * @see `getLocaleNumberSymbol()` + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export enum NumberSymbol { @@ -123,72 +186,114 @@ export enum NumberSymbol { * Decimal separator. * For `en-US`, the dot character. * Example : 2,345`.`67 + * + * 小数点分隔符。对于 `en-US`,是点字符。例如:2,345`.`67 + * */ Decimal, /** * Grouping separator, typically for thousands. * For `en-US`, the comma character. * Example: 2`,`345.67 + * + * 分组分隔符,通常为千位。对于 `en-US`,是逗号字符。例如:2`,`345.67 + * */ Group, /** * List-item separator. * Example: "one, two, and three" + * + * 列表项分隔符。例如:"one, two, and three" + * */ List, /** * Sign for percentage (out of 100). * Example: 23.4% + * + * 百分号(最大为 100)。例如:23.4% + * */ PercentSign, /** * Sign for positive numbers. * Example: +23 + * + * 正数的符号。例如:+23 + * */ PlusSign, /** * Sign for negative numbers. * Example: -23 + * + * 负数的符号。例如:-23 + * */ MinusSign, /** * Computer notation for exponential value (n times a power of 10). * Example: 1.2E3 + * + * 指数值的计算机表示法(10 的 n 次幂)。例如:1.2E3 + * */ Exponential, /** * Human-readable format of exponential. * Example: 1.2x103 + * + * 可读的指数格式。例如:1.2x103 + * */ SuperscriptingExponent, /** * Sign for permille (out of 1000). * Example: 23.4‰ + * + * 千分号(最大为 1000)。例如:23.4‰ + * */ PerMille, /** * Infinity, can be used with plus and minus. * Example: ∞, +∞, -∞ + * + * 无穷大,可与正负一起使用。例如:∞,+∞,-∞ + * */ Infinity, /** * Not a number. * Example: NaN + * + * 非数字。例如:NaN + * */ NaN, /** * Symbol used between time units. * Example: 10:52 + * + * 时间单位之间使用的符号。例如:10:52 + * */ TimeSeparator, /** * Decimal separator for currency values (fallback to `Decimal`). * Example: $2,345.67 + * + * 货币值的小数分隔符(回退为 `Decimal` )。例如:$2,345.67 + * */ CurrencyDecimal, /** * Group separator for currency values (fallback to `Group`). * Example: $2,345.67 + * + * 货币值的组分隔符(回退为 `Group` )。例如:$2,345.67 + * */ CurrencyGroup } @@ -196,6 +301,8 @@ export enum NumberSymbol { /** * The value for each day of the week, based on the `en-US` locale * + * 一周中每一天的值(基于 `en-US` 语言环境) + * * @publicApi */ export enum WeekDay { @@ -211,10 +318,21 @@ export enum WeekDay { /** * Retrieves the locale ID from the currently loaded locale. * The loaded locale could be, for example, a global one rather than a regional one. + * + * 从当前已加载的语言环境中检索语言环境 ID。加载的语言环境也可能是全球语言环境,而不是区域性语言环境。 + * * @param locale A locale code, such as `fr-FR`. + * + * 语言环境代码,例如 `fr-FR` 。 + * * @returns The locale code. For example, `fr`. + * + * 语言环境代码。例如, `fr` 。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleId(locale: string): string { @@ -224,12 +342,28 @@ export function getLocaleId(locale: string): string { /** * Retrieves day period strings for the given locale. * + * 检索给定语言环境的一天时段字符串。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @param formStyle The required grammatical form. + * + * 所需的语法形式。 + * * @param width The required character width. + * + * 所需的字符宽度。 + * * @returns An array of localized period strings. For example, `[AM, PM]` for `en-US`. + * + * 本地化的区间字符串数组。例如,`en-US` `[AM, PM]` 。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleDayPeriods( @@ -245,13 +379,29 @@ export function getLocaleDayPeriods( /** * Retrieves days of the week for the given locale, using the Gregorian calendar. * + * 使用公历来检索给定语言环境下的星期几。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @param formStyle The required grammatical form. + * + * 所需的语法形式。 + * * @param width The required character width. + * + * 所需的字符宽度。 + * * @returns An array of localized name strings. * For example,`[Sunday, Monday, ... Saturday]` for `en-US`. + * + * 本地化名称字符串的数组。例如,`en-US` `[Sunday, Monday, ... Saturday]` 。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleDayNames( @@ -266,13 +416,29 @@ export function getLocaleDayNames( /** * Retrieves months of the year for the given locale, using the Gregorian calendar. * + * 使用公历来检索给定语言环境下一年中的月份。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @param formStyle The required grammatical form. + * + * 所需的语法形式。 + * * @param width The required character width. + * + * 所需的字符宽度。 + * * @returns An array of localized name strings. * For example, `[January, February, ...]` for `en-US`. + * + * 本地化名称字符串的数组,例如,对于 `en-US` 是 `[January, February, ...]`。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleMonthNames( @@ -286,13 +452,27 @@ export function getLocaleMonthNames( /** * Retrieves Gregorian-calendar eras for the given locale. + * + * 检索给定语言环境的格里高利历日历。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @param width The required character width. + * + * 所需的字符宽度。 + * * @returns An array of localized era strings. * For example, `[AD, BC]` for `en-US`. + * + * 本地化年代字符串的数组。例如,对于 `en-US`,是 `[AD, BC]`。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleEraNames( @@ -305,12 +485,22 @@ export function getLocaleEraNames( /** * Retrieves the first day of the week for the given locale. * + * 检索给定语言环境中一周的第一天。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @returns A day index number, using the 0-based week-day index for `en-US` * (Sunday = 0, Monday = 1, ...). * For example, for `fr-FR`, returns 1 to indicate that the first day is Monday. + * + * 工作日索引号,使用基于 0 的 `en-US` 的工作日索引(星期日= 0,星期一= 1,...)。例如,对于 `fr-FR` ,返回 1 表示第一天是星期一。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleFirstDayOfWeek(locale: string): WeekDay { @@ -321,10 +511,20 @@ export function getLocaleFirstDayOfWeek(locale: string): WeekDay { /** * Range of week days that are considered the week-end for the given locale. * + * 在给定语言环境中被视为周末的工作日范围。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @returns The range of day values, `[startDay, endDay]`. + * + * 日期值的范围 `[startDay, endDay]` 。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleWeekEndRange(locale: string): [WeekDay, WeekDay] { @@ -335,12 +535,26 @@ export function getLocaleWeekEndRange(locale: string): [WeekDay, WeekDay] { /** * Retrieves a localized date-value formating string. * + * 检索本地化的日期-值格式字符串。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @param width The format type. + * + * 格式类型。 + * * @returns The localized formating string. + * + * 本地化的格式字符串。 + * * @see `FormatWidth` + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleDateFormat(locale: string, width: FormatWidth): string { @@ -351,11 +565,26 @@ export function getLocaleDateFormat(locale: string, width: FormatWidth): string /** * Retrieves a localized time-value formatting string. * + * 检索本地化的时间值格式字符串。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @param width The format type. + * + * 格式类型。 + * * @returns The localized formatting string. + * + * 本地化的格式字符串。 + * * @see `FormatWidth` + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) + * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ @@ -367,12 +596,26 @@ export function getLocaleTimeFormat(locale: string, width: FormatWidth): string /** * Retrieves a localized date-time formatting string. * + * 检索本地化的日期时间格式字符串。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @param width The format type. + * + * 格式类型。 + * * @returns The localized formatting string. + * + * 本地化的格式字符串。 + * * @see `FormatWidth` + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleDateTimeFormat(locale: string, width: FormatWidth): string { @@ -383,12 +626,27 @@ export function getLocaleDateTimeFormat(locale: string, width: FormatWidth): str /** * Retrieves a localized number symbol that can be used to replace placeholders in number formats. + * + * 检索本地化的数字符号,该符号可用于替换数字格式的占位符。 + * * @param locale The locale code. + * + * 语言环境代码。 + * * @param symbol The symbol to localize. + * + * 要本地化的符号。 + * * @returns The character for the localized symbol. + * + * 本地化符号的字符。 + * * @see `NumberSymbol` + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleNumberSymbol(locale: string, symbol: NumberSymbol): string { @@ -407,36 +665,67 @@ export function getLocaleNumberSymbol(locale: string, symbol: NumberSymbol): str /** * Retrieves a number format for a given locale. * + * 检索给定语言环境下的数字格式。 + * * Numbers are formatted using patterns, like `#,###.00`. For example, the pattern `#,###.00` * when used to format the number 12345.678 could result in "12'345,678". That would happen if the * grouping separator for your language is an apostrophe, and the decimal separator is a comma. * + * 数字会以类似 `#,###.00` 的模式进行格式化。例如,模式 `#,###.00` 用于格式化数字 12345.678 时可能的结果是 “12'345,678”。如果你的语言的分组分隔符是撇号,而十进制分隔符是逗号,就会是这样的。 + * * Important: The characters `.` `,` `0` `#` (and others below) are special placeholders * that stand for the decimal separator, and so on, and are NOT real characters. * You must NOT "translate" the placeholders. For example, don't change `.` to `,` even though in * your language the decimal point is written with a comma. The symbols should be replaced by the * local equivalents, using the appropriate `NumberSymbol` for your language. * + * *重要:*`.` `,` `0` `#`(以及以下的)字符是特殊的占位符,它们代表数字分隔符等,而不是真实的字符。你绝不能“翻译”这些占位符。例如,不要把 `.` 修改成 `,`,虽然在你的语言中小数点分隔符是写成逗号的。该符号会被其本地化等价物替换,也就是适合你的语言的 `NumberSymbol`。 + * * Here are the special characters used in number patterns: * + * 以下是数字模式中使用的特殊字符: + * * | Symbol | Meaning | * |--------|---------| + * | 符号 | 含义 | * | . | Replaced automatically by the character used for the decimal point. | + * | . | 自动替换为用作小数点的字符。 | * | , | Replaced by the "grouping" (thousands) separator. | + * | . | 替换为(千)“分组”分隔符。 | * | 0 | Replaced by a digit (or zero if there aren't enough digits). | + * | 0 | 替换为一个数字(如果没有足够的数字,则为零)。 | * | # | Replaced by a digit (or nothing if there aren't enough). | + * | # | 用数字代替(如果数字不足,则不进行任何替换)。 | * | ¤ | Replaced by a currency symbol, such as $ or USD. | + * | ¤ | 替换为货币符号,例如 $ 或 USD。 | * | % | Marks a percent format. The % symbol may change position, but must be retained. | + * | % | 标记百分比格式。%符号可能会更改位置,但必须保留。 | * | E | Marks a scientific format. The E symbol may change position, but must be retained. | + * | E | 标记科学计数法格式。 E 符号可能会改变位置,但必须保留。 | * | ' | Special characters used as literal characters are quoted with ASCII single quotes. | + * | ' | 表示文本字面量的特殊字符,用 ASCII 单引号引起来。 | * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @param type The type of numeric value to be formatted (such as `Decimal` or `Currency`.) + * + * 要格式化的数值类型(例如 `Decimal` 或 `Currency`)。 + * * @returns The localized format string. + * + * 本地化的格式字符串。 + * * @see `NumberFormatStyle` * @see [CLDR website](http://cldr.unicode.org/translation/number-patterns) + * + * [CLDR 官网](http://cldr.unicode.org/translation/number-patterns) + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleNumberFormat(locale: string, type: NumberFormatStyle): string { @@ -448,11 +737,21 @@ export function getLocaleNumberFormat(locale: string, type: NumberFormatStyle): * Retrieves the symbol used to represent the currency for the main country * corresponding to a given locale. For example, '$' for `en-US`. * + * 检索用于表示与给定语言环境对应的主要国家/地区的货币的符号。对于 `en-US` 为 `$`。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @returns The localized symbol character, * or `null` if the main country cannot be determined. + * + * 本地化的符号字符;如果无法确定主要国家则为 `null`。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleCurrencySymbol(locale: string): string|null { @@ -463,11 +762,22 @@ export function getLocaleCurrencySymbol(locale: string): string|null { /** * Retrieves the name of the currency for the main country corresponding * to a given locale. For example, 'US Dollar' for `en-US`. + * + * 检索与给定语言环境相对应的主要国家/地区的货币名称。对于 `en-US` 是 “US Dollar”。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @returns The currency name, * or `null` if the main country cannot be determined. + * + * 货币名称;如果无法确定主要国家/地区,则为 `null`。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleCurrencyName(locale: string): string|null { @@ -478,11 +788,20 @@ export function getLocaleCurrencyName(locale: string): string|null { /** * Retrieves the default currency code for the given locale. * + * 检索给定语言环境的默认货币代码。 + * * The default is defined as the first currency which is still in use. * + * 默认值定义为仍在使用的第一种货币。 + * * @param locale The code of the locale whose currency code we want. + * + * 我们想要获取货币代码的语言环境的代码。 + * * @returns The code of the default currency for the given locale. * + * 给定语言环境的默认货币代码。 + * * @publicApi */ export function getLocaleCurrencyCode(locale: string): string|null { @@ -491,9 +810,21 @@ export function getLocaleCurrencyCode(locale: string): string|null { /** * Retrieves the currency values for a given locale. + * + * 获取给定语言环境的货币值。 + * * @param locale A locale code for the locale format rules to use. + * + * 语言格式规则使用的语言环境代码。 + * * @returns The currency values. + * + * 货币值。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) + * + * [国际化(i18n)指南](guide/i18n) + * */ function getLocaleCurrencies(locale: string): {[code: string]: CurrenciesSymbols} { const data = ɵfindLocaleData(locale); @@ -502,6 +833,7 @@ function getLocaleCurrencies(locale: string): {[code: string]: CurrenciesSymbols /** * @alias core/ɵgetLocalePluralCase + * * @publicApi */ export const getLocalePluralCase: (locale: string) => ((value: number) => Plural) = @@ -519,22 +851,38 @@ function checkFullData(data: any) { * Retrieves locale-specific rules used to determine which day period to use * when more than one period is defined for a locale. * + * 检索特定于语言环境的规则,该规则用于确定在为一个语言环境中定义了多个时段时要使用的一天时段。 + * * There is a rule for each defined day period. The * first rule is applied to the first day period and so on. * Fall back to AM/PM when no rules are available. * + * 每个预定义的一天时段都有一个规则。第一条规则适用于第一个一天时段,依此类推。如果没有可用的规则,请回退为 AM / PM。 + * * A rule can specify a period as time range, or as a single time value. * + * 本规则可以将时间段指定为时间范围或单个时间值。 + * * This functionality is only available when you have loaded the full locale data. * See the ["I18n guide"](guide/i18n#i18n-pipes). * + * 仅当你加载了完整的语言环境数据时,此功能才可用。请参阅 [“I18n 指南”](guide/i18n#i18n-pipes) 。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @returns The rules for the locale, a single time value or array of *from-time, to-time*, * or null if no periods are available. * + * 语言环境的规则,单个时间值或 *from-time,to-time* 或 null 的数组(如果没有可用时段)。 + * * @see `getLocaleExtraDayPeriods()` + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleExtraDayPeriodRules(locale: string): (Time|[Time, Time])[] { @@ -554,16 +902,34 @@ export function getLocaleExtraDayPeriodRules(locale: string): (Time|[Time, Time] * in different languages. * For example, for `en-US`, periods are morning, noon, afternoon, evening, and midnight. * + * 检索特定于语言环境的一天时段,该时段大致指示如何用不同的语言分解一天。例如,对于 `en-US`,这些时段为 morning、noon、afternoon、evening 和 midnight。 + * * This functionality is only available when you have loaded the full locale data. * See the ["I18n guide"](guide/i18n#i18n-pipes). * + * 仅当你加载了完整的语言环境数据时,此功能才可用。请参阅 [“I18n 指南”](guide/i18n#i18n-pipes) 。 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @param formStyle The required grammatical form. + * + * 所需的语法形式。 + * * @param width The required character width. + * + * 所需的字符宽度。 + * * @returns The translated day-period strings. + * + * 翻译后的一天时段字符串。 + * * @see `getLocaleExtraDayPeriodRules()` * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getLocaleExtraDayPeriods( @@ -580,10 +946,23 @@ export function getLocaleExtraDayPeriods( /** * Retrieves the writing direction of a specified locale + * + * 检索指定语言环境的书写方向 + * * @param locale A locale code for the locale format rules to use. + * + * 用于要使用的语言环境格式规则的语言环境代码。 + * * @publicApi + * * @returns 'rtl' or 'ltr' + * + * 'rtl' 或 'ltr' + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) + * + * [国际化(i18n)指南](guide/i18n) + * */ export function getLocaleDirection(locale: string): 'ltr'|'rtl' { const data = ɵfindLocaleData(locale); @@ -593,14 +972,29 @@ export function getLocaleDirection(locale: string): 'ltr'|'rtl' { /** * Retrieves the first value that is defined in an array, going backwards from an index position. * + * 检索数组中定义的第一个值,从索引位置开始向后找。 + * * To avoid repeating the same data (as when the "format" and "standalone" forms are the same) * add the first value to the locale data arrays, and add other values only if they are different. * + * 为避免重复相同的数据(比如当 "format" 和 "standalone" 的格式相同时),将第一个值添加到语言环境数据数组,并仅在它们不同时添加其他值。 + * * @param data The data array to retrieve from. + * + * 要检索的数据数组。 + * * @param index A 0-based index into the array to start from. + * + * 从 0 开始的数组索引。 + * * @returns The value immediately before the given index position. + * + * 给定索引位置之前的值。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ function getLastDefinedValue(data: T[], index: number): T { @@ -615,6 +1009,8 @@ function getLastDefinedValue(data: T[], index: number): T { /** * Represents a time value with hours and minutes. * + * 用小时和分钟表示的时间值。 + * * @publicApi */ export type Time = { @@ -635,16 +1031,33 @@ function extractTime(time: string): Time { /** * Retrieves the currency symbol for a given currency code. * + * 检索给定货币代码的货币符号。 + * * For example, for the default `en-US` locale, the code `USD` can * be represented by the narrow symbol `$` or the wide symbol `US$`. * + * 例如,对于默认 `en-US` 语言环境,代码 `USD` 可以由窄符号 `$` 或宽符号 `US$` 表示。 + * * @param code The currency code. + * + * 货币代码。 + * * @param format The format, `wide` or `narrow`. + * + * 格式,如 `wide` 或 `narrow` 。 + * * @param locale A locale code for the locale format rules to use. * + * 要用作语言环境格式规则的语言环境代码。 + * * @returns The symbol, or the currency code if no symbol is available. + * + * 符号,或货币代码(如果没有可用的符号)。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getCurrencySymbol(code: string, format: 'wide'|'narrow', locale = 'en'): string { @@ -665,10 +1078,20 @@ const DEFAULT_NB_OF_CURRENCY_DIGITS = 2; * Reports the number of decimal digits for a given currency. * The value depends upon the presence of cents in that particular currency. * + * 报告给定货币的小数位数。其值取决于该特定货币中分币是否存在。 + * * @param code The currency code. + * + * 货币代码。 + * * @returns The number of decimal digits, typically 0 or 2. + * + * 小数位数,通常为 0 或 2。 + * * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n) * + * [国际化(i18n)指南](guide/i18n) + * * @publicApi */ export function getNumberOfCurrencyDigits(code: string): number { diff --git a/packages/common/src/i18n/localization.ts b/packages/common/src/i18n/localization.ts index 096cadccbb..61b83d4dc9 100644 --- a/packages/common/src/i18n/localization.ts +++ b/packages/common/src/i18n/localization.ts @@ -48,6 +48,8 @@ export function getPluralCategory( /** * Returns the plural case based on the locale * + * 根据语言环境返回复数形式 + * * @publicApi */ @Injectable() diff --git a/packages/common/src/location/hash_location_strategy.ts b/packages/common/src/location/hash_location_strategy.ts index 5f06a98bd5..35a526c25f 100644 --- a/packages/common/src/location/hash_location_strategy.ts +++ b/packages/common/src/location/hash_location_strategy.ts @@ -20,13 +20,19 @@ import {joinWithSlash, normalizeQueryParams} from './util'; * [hash fragment](https://en.wikipedia.org/wiki/Uniform_Resource_Locator#Syntax) * of the browser's URL. * + * 此 {@link LocationStrategy} 用来配置 {@link Location} 服务,以便在浏览器 URL 的 [hash 片段](https://en.wikipedia.org/wiki/Uniform_Resource_Locator#Syntax)中表示其状态。 + * * For instance, if you call `location.go('/foo')`, the browser's URL will become * `example.com#/foo`. * + * 例如,如果你调用 `location.go('/foo')` ,则浏览器的 URL 将变为 `example.com#/foo` 。 + * * @usageNotes * * ### Example * + * ### 例子 + * * {@example common/location/ts/hash_location_component.ts region='LocationComponent'} * * @publicApi diff --git a/packages/common/src/location/location.ts b/packages/common/src/location/location.ts index b0c2ce39df..54cc5c7a81 100644 --- a/packages/common/src/location/location.ts +++ b/packages/common/src/location/location.ts @@ -61,6 +61,8 @@ export interface PopStateEvent { * * ### Example * + * ### 例子 + * * * @@ -122,7 +124,13 @@ export class Location { /** * Reports the current state of the location history. + * + * 报告位置历史记录的当前状态。 + * * @returns The current value of the `history.state` object. + * + * `history.state` 对象的当前值。 + * */ getState(): unknown { return this._platformLocation.getState(); @@ -175,6 +183,8 @@ export class Location { * before normalizing. Adds a hash if `HashLocationStrategy` is * in use, or the `APP_BASE_HREF` if the `PathLocationStrategy` is in use. * + * 标准化外部 URL 路径。如果给定的 URL 并非以斜杠( `'/'` )开头,就会在规范化之前添加一个。如果使用 `HashLocationStrategy` 则添加哈希;如果使用 `PathLocationStrategy` 则添加 `APP_BASE_HREF`。 + * * @param url String representing a URL. * * 表示一个 URL。 @@ -264,7 +274,12 @@ export class Location { * Registers a URL change listener. Use to catch updates performed by the Angular * framework that are not detectible through "popstate" or "hashchange" events. * + * 注册 URL 更改监听器。被 Angular 框架用于捕获那些无法通过 “popstate” 或 “hashchange” 事件检测到的更新。 + * * @param fn The change handler function, which take a URL and a location history state. + * + * 更改处理器函数,接受 URL 和位置历史记录的状态。 + * */ onUrlChange(fn: (url: string, state: unknown) => void) { this._urlChangeListeners.push(fn); @@ -327,8 +342,12 @@ export class Location { * 给定 url 的两个部分,把它们连接(join)在一起,如有必要则添加一个斜杠。 * * @param start URL string + * + * URL 字符串 + * * @param end URL string * + * URL 字符串 * * @returns The joined URL string. * @@ -347,6 +366,8 @@ export class Location { * * @param url URL string. * + * URL 字符串。 + * * @returns The URL string, modified if needed. * * 返回一个 URL 字符串,如果有结尾斜杠,则移除,否则原样返回。 diff --git a/packages/common/src/location/location_strategy.ts b/packages/common/src/location/location_strategy.ts index 3d9bc0e05f..23156ec555 100644 --- a/packages/common/src/location/location_strategy.ts +++ b/packages/common/src/location/location_strategy.ts @@ -16,16 +16,24 @@ import {joinWithSlash, normalizeQueryParams} from './util'; * Angular provides two strategies: * `HashLocationStrategy` and `PathLocationStrategy`. * + * 使 `Location` 服务能够从浏览器的 URL 读取路由状态。 Angular 提供了两种策略: `HashLocationStrategy` 和 `PathLocationStrategy` 。 + * * Applications should use the `Router` or `Location` services to * interact with application route state. * + * 应用程序应使用 `Router` 或 `Location` 服务与应用程序的路由状态进行交互。 + * * For instance, `HashLocationStrategy` produces URLs like * http://example.com#/foo, * and `PathLocationStrategy` produces * http://example.com/foo as an equivalent URL. * + * 例如,`HashLocationStrategy` 会处理像 http://example.com#/foo 这样的 URL,而 `PathLocationStrategy` 会处理像 http://example.com/foo 这样的等价 URL。 + * * See these two classes for more. * + * 有关更多信息,请参见这两个类。 + * * @publicApi */ @Injectable({providedIn: 'root', useFactory: provideLocationStrategy}) @@ -54,11 +62,15 @@ export function provideLocationStrategy(platformLocation: PlatformLocation) { * The base href is the URL prefix that should be preserved when generating * and recognizing URLs. * + * 预定义的 [DI 令牌](guide/glossary#di-token),用于和 `PathLocationStrategy` 一起使用的 base href。base href 是在生成和识别 URL 时应保留的 URL 前缀。 + * * @usageNotes * * The following example shows how to use this token to configure the root app injector * with a base href value, so that the DI framework can supply the dependency anywhere in the app. * + * 以下示例演示了如何使用此令牌为基本应用注入器配置 base href 值,以便 DI 框架可以在应用中的任何位置提供依赖项。 + * * ```typescript * import {Component, NgModule} from '@angular/core'; * import {APP_BASE_HREF} from '@angular/common'; @@ -80,26 +92,38 @@ export const APP_BASE_HREF = new InjectionToken('appBaseHref'); * [path](https://en.wikipedia.org/wiki/Uniform_Resource_Locator#Syntax) of the * browser's URL. * + * 此 {@link LocationStrategy} 用来配置 {@link Location} 服务,以便在浏览器 URL 的 [path](https://en.wikipedia.org/wiki/Uniform_Resource_Locator#Syntax) 中表示其状态。 + * * If you're using `PathLocationStrategy`, you must provide a {@link APP_BASE_HREF} * or add a `` element to the document. * + * 如果你使用 `PathLocationStrategy` ,则必须提供一个 {@link APP_BASE_HREF} 或在文档中添加 ``。 + * * For instance, if you provide an `APP_BASE_HREF` of `'/my/app/'` and call * `location.go('/foo')`, the browser's URL will become * `example.com/my/app/foo`. To ensure all relative URIs resolve correctly, * the `` and/or `APP_BASE_HREF` should end with a `/`. * + * 例如,如果你提供的 `APP_BASE_HREF` 是 `'/my/app/'`,并调用 `location.go('/foo')`,则浏览器的 URL 将变为 `example.com/my/app/foo`。为了确保所有相对 URI 都能正确解析,`` 和/或 `APP_BASE_HREF` 都应该以 `/` 结尾。 + * * Similarly, if you add `` to the document and call * `location.go('/foo')`, the browser's URL will become * `example.com/my/app/foo`. * + * 同样,如果将 `` 添加到文档中并调用 `location.go('/foo')` ,则浏览器的 URL 将变为 `example.com/my/app/foo` 。 + * * Note that when using `PathLocationStrategy`, neither the query nor * the fragment in the `` will be preserved, as outlined * by the [RFC](https://tools.ietf.org/html/rfc3986#section-5.2.2). * + * 请注意,使用 `PathLocationStrategy` 时,如 [RFC](https://tools.ietf.org/html/rfc3986#section-5.2.2) 所述,查询和 `` 的片段部分都不会保留。 + * * @usageNotes * * ### Example * + * ### 例子 + * * {@example common/location/ts/path_location_component.ts region='LocationComponent'} * * @publicApi diff --git a/packages/common/src/location/platform_location.ts b/packages/common/src/location/platform_location.ts index 539bbb5a7a..81c762ba4f 100644 --- a/packages/common/src/location/platform_location.ts +++ b/packages/common/src/location/platform_location.ts @@ -14,6 +14,8 @@ import {DOCUMENT} from '../dom_tokens'; * This class should not be used directly by an application developer. Instead, use * {@link Location}. * + * 此类不应由应用程序开发人员直接使用。而应使用 {@link Location}。 + * * `PlatformLocation` encapsulates all calls to DOM APIs, which allows the Router to be * platform-agnostic. * This means that we can have different implementation of `PlatformLocation` for the different @@ -21,15 +23,21 @@ import {DOCUMENT} from '../dom_tokens'; * implementation specific to the browser environment, while `@angular/platform-server` provides * one suitable for use with server-side rendering. * + * `PlatformLocation` 封装了对 DOM API 的所有调用,这可以让路由器与平台无关。这意味着我们可以为 Angular 支持的不同平台提供 `PlatformLocation` 的不同实现。例如, `@angular/platform-browser` 提供了特定于浏览器环境的实现,而 `@angular/platform-server` 提供了适合与服务器端渲染一起使用的实现。 + * * The `PlatformLocation` class is used directly by all implementations of {@link LocationStrategy} * when they need to interact with the DOM APIs like pushState, popState, etc. * + * {@link LocationStrategy} 的所有实现在需要与 DOM API(例如 pushState,popState 等)进行交互时,都直接使用 `PlatformLocation` + * * {@link LocationStrategy} in turn is used by the {@link Location} service which is used directly * by the {@link Router} in order to navigate between routes. Since all interactions between {@link * Router} / * {@link Location} / {@link LocationStrategy} and DOM APIs flow through the `PlatformLocation` * class, they are all platform-agnostic. * + * {@link LocationStrategy} 由 {@link Router} 直接使用的 {@link Location} 服务使用,以便在路由之间导航。由于 {@link Router} / {@link Location} / {@link LocationStrategy}与 DOM API 之间的所有交互都是通过 `PlatformLocation` 类进行的,因此它们都是与平台无关的。 + * * @publicApi */ @Injectable({ @@ -68,6 +76,8 @@ export function useBrowserPlatformLocation() { * @description * Indicates when a location is initialized. * + * 指示何时初始化 location。 + * * @publicApi */ export const LOCATION_INITIALIZED = new InjectionToken>('Location Initialized'); @@ -76,6 +86,8 @@ export const LOCATION_INITIALIZED = new InjectionToken>('Location I * @description * A serializable version of the event from `onPopState` or `onHashChange` * + * 来自 `onPopState` 或 `onHashChange` 的事件的可序列化版本 + * * @publicApi */ export interface LocationChangeEvent { diff --git a/packages/common/src/pipes/case_conversion_pipes.ts b/packages/common/src/pipes/case_conversion_pipes.ts index 8985d7edfa..0a7222efad 100644 --- a/packages/common/src/pipes/case_conversion_pipes.ts +++ b/packages/common/src/pipes/case_conversion_pipes.ts @@ -73,6 +73,7 @@ const unicodeWordMatch = * @see `UpperCasePipe` * * @usageNotes + * * The following example shows the result of transforming various strings into title case. * * 下面的例子示范了如何把多种字符串转成标题形式。 diff --git a/packages/common/src/pipes/date_pipe.ts b/packages/common/src/pipes/date_pipe.ts index 7706ff6f91..0e08f8540c 100644 --- a/packages/common/src/pipes/date_pipe.ts +++ b/packages/common/src/pipes/date_pipe.ts @@ -55,15 +55,17 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error'; * `'medium'`: 等价于 `'MMM d, y, h:mm:ss a'` (`Jun 15, 2015, 9:03:01 AM`). * * - `'long'`: equivalent to `'MMMM d, y, h:mm:ss a z'` (`June 15, 2015 at 9:03:01 AM + * GMT+1`). * - * `'long'`: 等价于 `'MMMM d, y, h:mm:ss a z'` (`June 15, 2015 at 9:03:01 AM + * `'long'`: 等价于 `'MMMM d, y, h:mm:ss a z'` (`June 15, 2015 at 9:03:01 AM + * GMT+1`)。 * - * GMT+1`). * - `'full'`: equivalent to `'EEEE, MMMM d, y, h:mm:ss a zzzz'` (`Monday, June 15, 2015 at + * 9:03:01 AM GMT+01:00`). * - * `'full'`: 等价于 `'EEEE, MMMM d, y, h:mm:ss a zzzz'` (`Monday, June 15, 2015 at + * `'full'`: 等价于 `'EEEE, MMMM d, y, h:mm:ss a zzzz'` (`Monday, June 15, 2015 at + * 9:03:01 AM GMT+01:00`)。 * - * 9:03:01 AM GMT+01:00`). * - `'shortDate'`: equivalent to `'M/d/yy'` (`6/15/15`). * * `'shortDate'`: 等价于 `'M/d/yy'` (`6/15/15`). @@ -110,73 +112,73 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error'; * 具体格式取决于区域设置。 * 标 `*` 的字段表示仅在特定区域的数据中才有效。 * - * | Field type字段类型 | Format格式 | Description说明 | Example Value范例值 | - * |--------------------|-------------|---------------------------------------------------------------|------------------------------------------------------------| - * | Era纪元 | G, GG & GGG | Abbreviated缩略| AD | - * | | GGGG | Wide全称| Anno Domini | - * | | GGGGG | Narrow最简| A | - * | Year | y | Numeric数字: minimum digits最小位数 | 2, 20, 201, 2017, 20173 | - * | | yy | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 02, 20, 01, 17, 73 | - * | | yyy | Numeric数字: 3 digits + zero padded数字 + 0 补位 | 002, 020, 201, 2017, 20173 | - * | | yyyy | Numeric数字: 4 digits or more + zero padded或更多数字 + 0 补位 | 0002, 0020, 0201, 2017, 20173 | - * | Week-numbering year| Y | Numeric: minimum digits | 2, 20, 201, 2017, 20173 | - * | 周日历年| Y | 数字: 最少化数字 | 2, 20, 201, 2017, 20173 | - * | | YY | Numeric: 2 digits + zero padded | 02, 20, 01, 17, 73 | - * | | YY | 数字:2字符+补零 | 02, 20, 01, 17, 73 | - * | | YYY | Numeric: 3 digits + zero padded | 002, 020, 201, 2017, 20173 | - * | | YYY | 数字:3字符+补零 | 002, 020, 201, 2017, 20173 | - * | | YYYY | Numeric: 4 digits or more + zero padded | 0002, 0020, 0201, 2017, 20173 | - * | | YYYY | 数字:4字符+补零 | 0002, 0020, 0201, 2017, 20173 | - * | Month | M | Numeric数字: 1 digit1 数字 | 9, 12 | - * | | MM | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 09, 12 | - * | | MMM | Abbreviated缩略| Sep | - * | | MMMM | Wide全称| September | - * | | MMMMM | Narrow最简| S | - * | Month standalone独立月份 | L | Numeric数字: 1 digit1 数字 | 9, 12 | - * | | LL | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 09, 12 | - * | | LLL | Abbreviated缩略| Sep | - * | | LLLL | Wide全称| September | - * | | LLLLL | Narrow最简| S | - * | Week of year年内周次 | w | Numeric数字: minimum digits最小位数 | 1... 53 | - * | | ww | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 01... 53 | - * | Week of month月内周次 | W | Numeric数字: 1 digit1 数字 | 1... 5 | - * | Day of month月内日 | d | Numeric数字: minimum digits最小位数 | 1 | - * | | dd | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 01 | - * | Week day周内日 | E, EE & EEE | Abbreviated缩略| Tue | - * | | EEEE | Wide全称| Tuesday | - * | | EEEEE | Narrow最简| T | - * | | EEEEEE | Short | Tu | - * | Period日内时段 | a, aa & aaa | Abbreviated缩略| am/pm or AM/PM | - * | | aaaa | Wide全称(fallback to `a` when missing)(缺少时等同于 `a`)| ante meridiem/post meridiem | - * | | aaaaa | Narrow最简| a/p | - * | Period*日内时段 | B, BB & BBB | Abbreviated缩略| mid. | - * | | BBBB | Wide全称| am, pm, midnight, noon, morning, afternoon, evening, night | - * | | BBBBB | Narrow最简| md | - * | Period standalone*独立时段 | b, bb & bbb | Abbreviated缩略| mid. | - * | | bbbb | Wide全称| am, pm, midnight, noon, morning, afternoon, evening, night | - * | | bbbbb | Narrow最简| md | - * | Hour 1-12小时(1-12) | h | Numeric数字: minimum digits最小位数 | 1, 12 | - * | | hh | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 01, 12 | - * | Hour 0-23小时(0-23) | H | Numeric数字: minimum digits最小位数 | 0, 23 | - * | | HH | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 00, 23 | - * | Minute | m | Numeric数字: minimum digits最小位数 | 8, 59 | - * | | mm | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 08, 59 | - * | Second | s | Numeric数字: minimum digits最小位数 | 0... 59 | - * | | ss | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 00... 59 | - * | Fractional seconds分数秒 | S | Numeric数字: 1 digit1 数字 | 0... 9 | - * | | SS | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 00... 99 | - * | | SSS | Numeric数字: 3 digits + zero padded数字 + 0 补位 (= milliseconds毫秒) | 000... 999 | - * | Zone时区 | z, zz & zzz | Short specific non location format (fallback to O)位置无关短格式(默认为0) | GMT-8 | - * | | zzzz | Long specific non location format (fallback to OOOO)位置无关长格式(默认为0000) | GMT-08:00 | - * | | Z, ZZ & ZZZ | ISO8601 basic format基本格式 | -0800 | - * | | ZZZZ | Long localized GMT format本地化 GMT 长格式 | GMT-8:00 | - * | | ZZZZZ | ISO8601 extended format + Z indicator for offset 0扩展格式 + 偏移为 0 时用 Z 表示 (= XXXXX) | -08:00 | - * | | O, OO & OOO | Short localized GMT format本地化 GMT 短格式 | GMT-8 | - * | | OOOO | Long localized GMT format本地化 GMT 长格式 | GMT-08:00 | + * | Field type字段类型 | Format格式 | Description说明 | Example Value范例值 | + * | -------------------------------- | ------------------------ | ----------------------------- | --------------------------------- | + * | Era纪元 | G, GG & GGG | Abbreviated缩略 | AD | + * | | GGGG | Wide全称 | Anno Domini | + * | | GGGGG | Narrow最简 | A | + * | Year | y | Numeric数字: minimum digits最小位数 | 2, 20, 201, 2017, 20173 | + * | | yy | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 02, 20, 01, 17, 73 | + * | | yyy | Numeric数字: 3 digits + zero padded数字 + 0 补位 | 002, 020, 201, 2017, 20173 | + * | | yyyy | Numeric数字: 4 digits or more + zero padded或更多数字 + 0 补位 | 0002, 0020, 0201, 2017, 20173 | + * | Week-numbering year | Y | Numeric: minimum digits | 2, 20, 201, 2017, 20173 | + * | 周日历年 | Y | 数字: 最少化数字 | 2, 20, 201, 2017, 20173 | + * | | YY | Numeric: 2 digits + zero padded | 02, 20, 01, 17, 73 | + * | | YY | 数字:2 字符+补零 | 02, 20, 01, 17, 73 | + * | | YYY | Numeric: 3 digits + zero padded | 002, 020, 201, 2017, 20173 | + * | | YYY | 数字:3 字符+补零 | 002, 020, 201, 2017, 20173 | + * | | YYYY | Numeric: 4 digits or more + zero padded | 0002, 0020, 0201, 2017, 20173 | + * | | YYYY | 数字:4 字符+补零 | 0002, 0020, 0201, 2017, 20173 | + * | Month | M | Numeric数字: 1 digit1 数字 | 9, 12 | + * | | MM | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 09, 12 | + * | | MMM | Abbreviated缩略 | Sep | + * | | MMMM | Wide全称 | September | + * | | MMMMM | Narrow最简 | S | + * | Month standalone独立月份 | L | Numeric数字: 1 digit1 数字 | 9, 12 | + * | | LL | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 09, 12 | + * | | LLL | Abbreviated缩略 | Sep | + * | | LLLL | Wide全称 | September | + * | | LLLLL | Narrow最简 | S | + * | Week of year年内周次 | w | Numeric数字: minimum digits最小位数 | 1... 53 | + * | | ww | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 01... 53 | + * | Week of month月内周次 | W | Numeric数字: 1 digit1 数字 | 1... 5 | + * | Day of month月内日 | d | Numeric数字: minimum digits最小位数 | 1 | + * | | dd | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 01 | + * | Week day周内日 | E, EE & EEE | Abbreviated缩略 | Tue | + * | | EEEE | Wide全称 | Tuesday | + * | | EEEEE | Narrow最简 | T | + * | | EEEEEE | Short | Tu | + * | Period日内时段 | a, aa & aaa | Abbreviated缩略 | am/pm or AM/PM | + * | | aaaa | Wide全称(fallback to `a` when missing)(缺少时等同于 `a`) | ante meridiem/post meridiem | + * | | aaaaa | Narrow最简 | a/p | + * | Period\*日内时段 | B, BB & BBB | Abbreviated缩略 | mid. | + * | | BBBB | Wide全称 | am, pm, midnight, noon, morning, afternoon, evening, night | + * | | BBBBB | Narrow最简 | md | + * | Period standalone\*独立时段 | b, bb & bbb | Abbreviated缩略 | mid. | + * | | bbbb | Wide全称 | am, pm, midnight, noon, morning, afternoon, evening, night | + * | | bbbbb | Narrow最简 | md | + * | Hour 1-12小时(1-12) | h | Numeric数字: minimum digits最小位数 | 1, 12 | + * | | hh | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 01, 12 | + * | Hour 0-23小时(0-23) | H | Numeric数字: minimum digits最小位数 | 0, 23 | + * | | HH | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 00, 23 | + * | Minute | m | Numeric数字: minimum digits最小位数 | 8, 59 | + * | | mm | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 08, 59 | + * | Second | s | Numeric数字: minimum digits最小位数 | 0... 59 | + * | | ss | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 00... 59 | + * | Fractional seconds分数秒 | S | Numeric数字: 1 digit1 数字 | 0... 9 | + * | | SS | Numeric数字: 2 digits + zero padded数字 + 0 补位 | 00... 99 | + * | | SSS | Numeric数字: 3 digits + zero padded数字 + 0 补位 (= milliseconds毫秒) | 000... 999 | + * | Zone时区 | z, zz & zzz | Short specific non location format (fallback to O)位置无关短格式(默认为 0) | GMT-8 | + * | | zzzz | Long specific non location format (fallback to OOOO)位置无关长格式(默认为 0000) | GMT-08:00 | + * | | Z, ZZ & ZZZ | ISO8601 basic format基本格式 | -0800 | + * | | ZZZZ | Long localized GMT format本地化 GMT 长格式 | GMT-8:00 | + * | | ZZZZZ | ISO8601 extended format + Z indicator for offset 0扩展格式 + 偏移为 0 时用 Z 表示 (= XXXXX) | -08:00 | + * | | O, OO & OOO | Short localized GMT format本地化 GMT 短格式 | GMT-8 | + * | | OOOO | Long localized GMT format本地化 GMT 长格式 | GMT-08:00 | * * Note that timezone correction is not applied to an ISO string that has no time component, such as "2016-09-19" * - * 请注意,时区校正不适用于没有时间部分的ISO字符串,例如“2016-09-19” + * 请注意,时区校正不适用于没有时间部分的 ISO 字符串,例如“2016-09-19” * * ### Format examples * @@ -243,7 +245,7 @@ export class DatePipe implements PipeTransform { * UTC/GMT or continental US timezone abbreviation. * When not supplied, uses the end-user's local system timezone. * - * 一个时区偏移(比如`'+0430'`)或标准的 UTC/GMT 或美国大陆时区的缩写。默认为最终用户机器上的本地系统时区。 + * 一个时区偏移(比如 `'+0430'`)或标准的 UTC/GMT 或美国大陆时区的缩写。默认为最终用户机器上的本地系统时区。 * * @param locale A locale code for the locale format rules to use. * When not supplied, uses the value of `LOCALE_ID`, which is `en-US` by default. diff --git a/packages/common/src/pipes/i18n_plural_pipe.ts b/packages/common/src/pipes/i18n_plural_pipe.ts index 252da96c3e..cf9c2e1a66 100644 --- a/packages/common/src/pipes/i18n_plural_pipe.ts +++ b/packages/common/src/pipes/i18n_plural_pipe.ts @@ -20,10 +20,14 @@ const _INTERPOLATION_REGEXP: RegExp = /#/g; * * Maps a value to a string that pluralizes the value according to locale rules. * + * 将值映射到根据语言环境规则对该值进行复数化的字符串。 + * * @usageNotes * * ### Example * + * ### 例子 + * * {@example common/pipes/ts/i18n_pipe.ts region='I18nPluralPipeComponent'} * * @publicApi @@ -34,10 +38,18 @@ export class I18nPluralPipe implements PipeTransform { /** * @param value the number to be formatted + * + * 要格式化的数字 + * * @param pluralMap an object that mimics the ICU format, see * http://userguide.icu-project.org/formatparse/messages. + * + * 模仿 ICU 格式的对象,请参见 。 + * * @param locale a `string` defining the locale to use (uses the current {@link LOCALE_ID} by * default). + * + * 定义要使用的语言环境的 `string`(默认情况下使用当前的 {@link LOCALE_ID})。 */ transform(value: number|null|undefined, pluralMap: {[count: string]: string}, locale?: string): string { diff --git a/packages/common/src/pipes/i18n_select_pipe.ts b/packages/common/src/pipes/i18n_select_pipe.ts index d5fac44493..7c45185cc0 100644 --- a/packages/common/src/pipes/i18n_select_pipe.ts +++ b/packages/common/src/pipes/i18n_select_pipe.ts @@ -15,13 +15,19 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error'; * * Generic selector that displays the string that matches the current value. * + * 通用选择器,用于显示与当前值匹配的字符串。 + * * If none of the keys of the `mapping` match the `value`, then the content * of the `other` key is returned when present, otherwise an empty string is returned. * + * 如果 `mapping` 中的任何键都不与 `value` 匹配,`other` 键的内容如果存在则返回,否则返回空字符串。 + * * @usageNotes * * ### Example * + * ### 例子 + * * {@example common/pipes/ts/i18n_pipe.ts region='I18nSelectPipeComponent'} * * @publicApi @@ -30,8 +36,14 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error'; export class I18nSelectPipe implements PipeTransform { /** * @param value a string to be internationalized. + * + * 要国际化的字符串。 + * * @param mapping an object that indicates the text that should be displayed * for different values of the provided `value`. + * + * 一个对象,指示对不同于所提供 `value` 的值应该显示的文本。 + * */ transform(value: string|null|undefined, mapping: {[key: string]: string}): string { if (value == null) return ''; diff --git a/packages/common/src/pipes/keyvalue_pipe.ts b/packages/common/src/pipes/keyvalue_pipe.ts index 163b83f3e6..caf62c9154 100644 --- a/packages/common/src/pipes/keyvalue_pipe.ts +++ b/packages/common/src/pipes/keyvalue_pipe.ts @@ -16,6 +16,8 @@ function makeKeyValuePair(key: K, value: V): KeyValue { * A key value pair. * Usually used to represent the key value pairs from a Map or Object. * + * 一个键值对。通常用于表示 Map 或 Object 中的键值对。 + * * @publicApi */ export interface KeyValue { @@ -29,16 +31,25 @@ export interface KeyValue { * * Transforms Object or Map into an array of key value pairs. * + * 将 Object 或 Map 转换为键值对数组。 + * * The output array will be ordered by keys. * By default the comparator will be by Unicode point value. * You can optionally pass a compareFn if your keys are complex types. * + * 输出数组将通过键名排序。默认情况下,比较器将使用 Unicode 点位值。如果你的键名是复杂类型,则可以选择传入一个 compareFn。 + * * @usageNotes + * * ### Examples * + * ### 例子 + * * This examples show how an Object or a Map can be iterated by ngFor with the use of this * keyvalue pipe. * + * 此示例演示了 ngFor 如何使用此键值管道对 Object 或 Map 进行迭代。 + * * {@example common/pipes/ts/keyvalue_pipe.ts region='KeyValuePipe'} * * @publicApi diff --git a/packages/common/src/pipes/number_pipe.ts b/packages/common/src/pipes/number_pipe.ts index 6d2f8bf2fc..4f4820ca03 100644 --- a/packages/common/src/pipes/number_pipe.ts +++ b/packages/common/src/pipes/number_pipe.ts @@ -45,6 +45,7 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error'; * @see `formatNumber()` * * @usageNotes + * * The following code shows how the pipe transforms numbers * into text strings, according to various format specifications, * where the caller's default locale is `en-US`. @@ -131,6 +132,7 @@ export class DecimalPipe implements PipeTransform { * @see `formatPercent()` * * @usageNotes + * * The following code shows how the pipe transforms numbers * into text strings, according to various format specifications, * where the caller's default locale is `en-US`. @@ -234,6 +236,7 @@ export class PercentPipe implements PipeTransform { * @see `formatCurrency()` * * @usageNotes + * * The following code shows how the pipe transforms numbers * into text strings, according to various format specifications, * where the caller's default locale is `en-US`. diff --git a/packages/common/src/platform_id.ts b/packages/common/src/platform_id.ts index eaf25fb31c..f944c4e6c1 100644 --- a/packages/common/src/platform_id.ts +++ b/packages/common/src/platform_id.ts @@ -13,6 +13,9 @@ export const PLATFORM_WORKER_UI_ID = 'browserWorkerUi'; /** * Returns whether a platform id represents a browser platform. + * + * 返回平台 ID 是否代表浏览器平台。 + * * @publicApi */ export function isPlatformBrowser(platformId: Object): boolean { @@ -21,6 +24,9 @@ export function isPlatformBrowser(platformId: Object): boolean { /** * Returns whether a platform id represents a server platform. + * + * 返回平台 ID 是否代表服务器平台。 + * * @publicApi */ export function isPlatformServer(platformId: Object): boolean { @@ -29,6 +35,9 @@ export function isPlatformServer(platformId: Object): boolean { /** * Returns whether a platform id represents a web worker app platform. + * + * 返回平台 ID 是否代表 Web Worker 应用平台。 + * * @publicApi */ export function isPlatformWorkerApp(platformId: Object): boolean { @@ -37,6 +46,9 @@ export function isPlatformWorkerApp(platformId: Object): boolean { /** * Returns whether a platform id represents a web worker UI platform. + * + * 返回平台 ID 是否代表 Web Worker UI 平台。 + * * @publicApi */ export function isPlatformWorkerUi(platformId: Object): boolean { diff --git a/packages/common/src/viewport_scroller.ts b/packages/common/src/viewport_scroller.ts index d3ff85d6fd..6569255e35 100644 --- a/packages/common/src/viewport_scroller.ts +++ b/packages/common/src/viewport_scroller.ts @@ -15,6 +15,8 @@ import {DOCUMENT} from './dom_tokens'; /** * Defines a scroll position manager. Implemented by `BrowserViewportScroller`. * + * 定义滚动位置管理器。由 `BrowserViewportScroller` 实现。 + * * @publicApi */ export abstract class ViewportScroller { @@ -29,27 +31,50 @@ export abstract class ViewportScroller { /** * Configures the top offset used when scrolling to an anchor. + * + * 配置滚动到锚点时使用的顶部偏移量。 + * * @param offset A position in screen coordinates (a tuple with x and y values) * or a function that returns the top offset position. * + * 屏幕坐标中的位置(具有 x 和 y 值的元组)或返回顶部偏移位置的函数。 + * */ abstract setOffset(offset: [number, number]|(() => [number, number])): void; /** * Retrieves the current scroll position. + * + * 检索当前滚动位置。 + * * @returns A position in screen coordinates (a tuple with x and y values). + * + * 屏幕坐标中的位置(具有 x 和 y 值的元组)。 + * */ abstract getScrollPosition(): [number, number]; /** * Scrolls to a specified position. + * + * 滚动到指定位置。 + * * @param position A position in screen coordinates (a tuple with x and y values). + * + * 屏幕坐标中的位置(具有 x 和 y 值的元组)。 + * */ abstract scrollToPosition(position: [number, number]): void; /** * Scrolls to an anchor element. + * + * 滚动到锚点元素。 + * * @param anchor The ID of the anchor element. + * + * 锚点元素的 ID。 + * */ abstract scrollToAnchor(anchor: string): void; @@ -57,6 +82,9 @@ export abstract class ViewportScroller { * Disables automatic scroll restoration provided by the browser. * See also [window.history.scrollRestoration * info](https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration). + * + * 禁用浏览器提供的自动滚动恢复功能。另请参见 [window.history.scrollRestoration 信息](https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration)。 + * */ abstract setHistoryScrollRestoration(scrollRestoration: 'auto'|'manual'): void; } diff --git a/packages/common/testing/src/location_mock.ts b/packages/common/testing/src/location_mock.ts index e7f5595ec9..343a4806e3 100644 --- a/packages/common/testing/src/location_mock.ts +++ b/packages/common/testing/src/location_mock.ts @@ -13,6 +13,8 @@ import {SubscriptionLike} from 'rxjs'; /** * A spy for {@link Location} that allows tests to fire simulated location events. * + * {@link Location} 的间谍对象,它允许测试者触发模拟的位置事件。 + * * @publicApi */ @Injectable() diff --git a/packages/common/testing/src/mock_location_strategy.ts b/packages/common/testing/src/mock_location_strategy.ts index 646534b7af..bc777d6f93 100644 --- a/packages/common/testing/src/mock_location_strategy.ts +++ b/packages/common/testing/src/mock_location_strategy.ts @@ -15,6 +15,8 @@ import {EventEmitter, Injectable} from '@angular/core'; * A mock implementation of {@link LocationStrategy} that allows tests to fire simulated * location events. * + * {@link LocationStrategy} 的模拟实现,允许测试触发模拟的 location 事件。 + * * @publicApi */ @Injectable() diff --git a/packages/common/testing/src/mock_platform_location.ts b/packages/common/testing/src/mock_platform_location.ts index b3c97ddf69..db21f04d82 100644 --- a/packages/common/testing/src/mock_platform_location.ts +++ b/packages/common/testing/src/mock_platform_location.ts @@ -81,6 +81,8 @@ function parseUrl(urlStr: string, baseHref: string) { /** * Mock platform location config * + * 模拟平台的 location 配置 + * * @publicApi */ export interface MockPlatformLocationConfig { @@ -91,6 +93,8 @@ export interface MockPlatformLocationConfig { /** * Provider for mock platform location config * + * 模拟平台 location 配置的提供者 + * * @publicApi */ export const MOCK_PLATFORM_LOCATION_CONFIG = @@ -99,6 +103,8 @@ export const MOCK_PLATFORM_LOCATION_CONFIG = /** * Mock implementation of URL state. * + * URL 状态的模拟实现。 + * * @publicApi */ @Injectable() diff --git a/packages/common/upgrade/src/location_shim.ts b/packages/common/upgrade/src/location_shim.ts index 4e46269a06..284caed484 100644 --- a/packages/common/upgrade/src/location_shim.ts +++ b/packages/common/upgrade/src/location_shim.ts @@ -26,8 +26,12 @@ const DEFAULT_PORTS: {[key: string]: number} = { * Location service that provides a drop-in replacement for the $location service * provided in AngularJS. * + * 位置服务,提供对 AngularJS 中提供的 $location 服务的直接替代品。 + * * @see [Using the Angular Unified Location Service](guide/upgrade#using-the-unified-angular-location-service) * + * [使用 Angular 统一位置服务](guide/upgrade#using-the-unified-angular-location-service) + * * @publicApi */ export class $locationShim { @@ -290,6 +294,9 @@ export class $locationShim { /** * This function emulates the $browser.state() function from AngularJS. It will cause * history.state to be cached unless changed with deep equality check. + * + * 此函数模拟 AngularJS 中的 $browser.state() 函数。除非使用深度相等性检查进行更改,否则它将导致 history.state 被缓存。 + * */ private browserState(): unknown { return this.cachedState; @@ -340,12 +347,22 @@ export class $locationShim { * `$locationChangeSuccess` events which fire when AngularJS updates its internally-referenced * version of the browser URL. * + * 注册对 URL 更改的监听器。该 API 用于捕获 AngularJS 框架执行的更新。`$locationChangeStart` 和 `$locationChangeSuccess` 事件的子集,这些事件在 AngularJS 更新其内部引用的浏览器 URL 版本时触发。 + * * It's possible for `$locationChange` events to happen, but for the browser URL * (window.location) to remain unchanged. This `onChange` callback will fire only when AngularJS * actually updates the browser URL (window.location). * + * `$locationChange` 事件有可能发生,但浏览器的 URL(window.location)保持不变。仅当 AngularJS 实际上更新浏览器 URL(window.location)时,才会触发此 `onChange` + * * @param fn The callback function that is triggered for the listener when the URL changes. + * + * URL 更改时为监听器触发的回调函数。 + * * @param err The callback function that is triggered when an error occurs. + * + * 发生错误时触发的回调函数。 + * */ onChange( fn: (url: string, state: unknown, oldUrl: string, oldState: unknown) => void, @@ -368,7 +385,12 @@ export class $locationShim { /** * Parses the provided URL, and sets the current URL to the parsed result. * + * 解析此 URL,并将当前 URL 设置为解析结果。 + * * @param url The URL string. + * + * URL 字符串。 + * */ $$parse(url: string) { let pathUrl: string|undefined; @@ -393,8 +415,16 @@ export class $locationShim { /** * Parses the provided URL and its relative URL. * + * 解析提供的 URL 及其相对 URL。 + * * @param url The full URL string. + * + * 完整的 URL 字符串。 + * * @param relHref A URL string relative to the full URL string. + * + * 相对于完整 URL 字符串的 URL 字符串。 + * */ $$parseLinkUrl(url: string, relHref?: string|null): boolean { // When relHref is passed, it should be a hash and is handled separately @@ -446,6 +476,7 @@ export class $locationShim { * rules specified in * [RFC 3986](https://tools.ietf.org/html/rfc3986). * + * 检索完整的 URL 表示形式,其中包含根据 [RFC 3986 中](https://tools.ietf.org/html/rfc3986) 指定的规则编码过的所有段。 * * ```js * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo @@ -461,6 +492,8 @@ export class $locationShim { * Retrieves the current URL, or sets a new URL. When setting a URL, * changes the path, search, and hash, and returns a reference to its own instance. * + * 检索当前 URL,或设置新 URL。设置 URL 时,更改路径、搜索和哈希,并返回对其自身实例的引用。 + * * ```js * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo * let url = $location.url(); @@ -491,6 +524,8 @@ export class $locationShim { /** * Retrieves the protocol of the current URL. * + * 检索当前 URL 的协议。 + * * ```js * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo * let protocol = $location.protocol(); @@ -504,9 +539,12 @@ export class $locationShim { /** * Retrieves the protocol of the current URL. * + * 检索当前 URL 的协议。 + * * In contrast to the non-AngularJS version `location.host` which returns `hostname:port`, this * returns the `hostname` portion only. * + * 与非 AngularJS 版本不同,其 `location.host` 会返回 `hostname:port` ,而这里会返回 `hostname` 部分。 * * ```js * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo @@ -527,6 +565,8 @@ export class $locationShim { /** * Retrieves the port of the current URL. * + * 检索当前 URL 的端口。 + * * ```js * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo * let port = $location.port(); @@ -541,9 +581,13 @@ export class $locationShim { * Retrieves the path of the current URL, or changes the path and returns a reference to its own * instance. * + * 检索当前 URL 的路径,或更改路径并返回对其自身实例的引用。 + * * Paths should always begin with forward slash (/). This method adds the forward slash * if it is missing. * + * 路径应始终以正斜杠(/)开头。如果缺少此斜杠,则此方法将添加它。 + * * ```js * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo * let path = $location.path(); @@ -571,6 +615,7 @@ export class $locationShim { * Retrieves a map of the search parameters of the current URL, or changes a search * part and returns a reference to its own instance. * + * 检索当前 URL 的搜索参数的映射,或更改搜索部分并返回对其自身实例的引用。 * * ```js * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo @@ -585,25 +630,41 @@ export class $locationShim { * @param {string|Object.|Object.>} search New search params - string or * hash object. * + * 新的搜索参数-字符串或哈希对象。 + * * When called with a single argument the method acts as a setter, setting the `search` component * of `$location` to the specified value. * + * 当使用单个参数调用它时,该方法会充当设置器,将 `$location` 的 `search` 组件设置为指定值。 + * * If the argument is a hash object containing an array of values, these values will be encoded * as duplicate search parameters in the URL. * + * 如果参数是包含值数组的哈希对象,则这些值将被编码为 URL 中的重复搜索参数。 + * * @param {(string|Number|Array|boolean)=} paramValue If `search` is a string or number, * then `paramValue` * will override only a single search property. * + * 如果 `search` 是字符串或数字,则 `paramValue` 将仅覆盖单个搜索属性。 + * * If `paramValue` is an array, it will override the property of the `search` component of * `$location` specified via the first argument. * + * 如果 `paramValue` 是一个数组,它将覆盖通过第一个参数指定的 `$location` 的 `search` 的部分。 + * * If `paramValue` is `null`, the property specified via the first argument will be deleted. * + * 如果 `paramValue` 为 `null` ,则将删除通过第一个参数指定的属性。 + * * If `paramValue` is `true`, the property specified via the first argument will be added with no * value nor trailing equal sign. * + * 如果 `paramValue` 为 `true` ,则将通过第一个参数指定的属性添加为无值或结尾等号。 + * * @return {Object} The parsed `search` object of the current URL, or the changed `search` object. + * + * 当前 URL 的已解析 `search` 对象,或更改后的 `search` 对象。 */ search(): {[key: string]: unknown}; search(search: string|number|{[key: string]: unknown}): this; @@ -653,6 +714,8 @@ export class $locationShim { * Retrieves the current hash fragment, or changes the hash fragment and returns a reference to * its own instance. * + * 检索当前哈希片段,或更改哈希片段并返回对其自身实例的引用。 + * * ```js * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue * let hash = $location.hash(); @@ -675,6 +738,9 @@ export class $locationShim { /** * Changes to `$location` during the current `$digest` will replace the current * history record, instead of adding a new one. + * + * 当前 `$digest` 期间对 `$location` 更改将替换当前历史记录,而不是添加新的记录。 + * */ replace(): this { this.$$replace = true; @@ -684,13 +750,18 @@ export class $locationShim { /** * Retrieves the history state object when called without any parameter. * + * 当不带任何参数调用时将检索历史状态对象。 + * * Change the history state object when called with one parameter and return `$location`. * The state object is later passed to `pushState` or `replaceState`. * + * 使用一个参数调用时将更改历史状态对象,并返回 `$location` 。状态对象随后传递给 `pushState` 或 `replaceState` 。 + * * This method is supported only in HTML5 mode and only in browsers supporting * the HTML5 History API methods such as `pushState` and `replaceState`. If you need to support * older browsers (like Android < 4.0), don't use this method. * + * 仅在 HTML5 模式下以及在支持 HTML5 History API 方法(例如 `pushState` 和 `replaceState`)的浏览器中才支持此方法。如果你需要支持较旧的浏览器(例如 Android <4.0),请不要使用此方法。 */ state(): unknown; state(state: unknown): this; @@ -708,6 +779,8 @@ export class $locationShim { * The factory function used to create an instance of the `$locationShim` in Angular, * and provides an API-compatiable `$locationProvider` for AngularJS. * + * Angular 中用于创建 `$locationShim` 实例的工厂函数,并为 AngularJS 提供与 API 兼容的 `$locationProvider`。 + * * @publicApi */ export class $locationShimProvider { @@ -718,6 +791,9 @@ export class $locationShimProvider { /** * Factory method that returns an instance of the $locationShim + * + * 返回 $locationShim 实例的工厂方法 + * */ $get() { return new $locationShim( @@ -728,6 +804,9 @@ export class $locationShimProvider { /** * Stub method used to keep API compatible with AngularJS. This setting is configured through * the LocationUpgradeModule's `config` method in your Angular app. + * + * 用于使 API 与 AngularJS 兼容的存根方法。此设置是通过 Angular 应用中 LocationUpgradeModule 的 `config` 方法配置的。 + * */ hashPrefix(prefix?: string) { throw new Error('Configure LocationUpgrade through LocationUpgradeModule.config method.'); @@ -736,6 +815,9 @@ export class $locationShimProvider { /** * Stub method used to keep API compatible with AngularJS. This setting is configured through * the LocationUpgradeModule's `config` method in your Angular app. + * + * 用于使 API 与 AngularJS 兼容的存根方法。此设置是通过 Angular 应用中 LocationUpgradeModule 的 `config` 方法配置的。 + * */ html5Mode(mode?: any) { throw new Error('Configure LocationUpgrade through LocationUpgradeModule.config method.'); diff --git a/packages/common/upgrade/src/location_upgrade_module.ts b/packages/common/upgrade/src/location_upgrade_module.ts index d8405b27c8..4c9001eb00 100644 --- a/packages/common/upgrade/src/location_upgrade_module.ts +++ b/packages/common/upgrade/src/location_upgrade_module.ts @@ -17,28 +17,45 @@ import {AngularJSUrlCodec, UrlCodec} from './params'; /** * Configuration options for LocationUpgrade. * + * LocationUpgrade 的配置选项。 + * * @publicApi */ export interface LocationUpgradeConfig { /** * Configures whether the location upgrade module should use the `HashLocationStrategy` * or the `PathLocationStrategy` + * + * 配置 location 升级模块应使用 `HashLocationStrategy` 还是 `PathLocationStrategy` + * */ useHash?: boolean; /** * Configures the hash prefix used in the URL when using the `HashLocationStrategy` + * + * 配置使用 `HashLocationStrategy` 时 URL 中要使用的哈希前缀 + * */ hashPrefix?: string; /** * Configures the URL codec for encoding and decoding URLs. Default is the `AngularJSCodec` + * + * 配置 URL 编解码器以对 URL 进行编码和解码。默认为 `AngularJSCodec` + * */ urlCodec?: typeof UrlCodec; /** * Configures the base href when used in server-side rendered applications + * + * 配置在服务器端渲染的应用程序中使用时的 base href + * */ serverBaseHref?: string; /** * Configures the base href when used in client-side rendered applications + * + * 配置在客户端渲染的应用程序中使用时的 base href + * */ appBaseHref?: string; } @@ -46,6 +63,8 @@ export interface LocationUpgradeConfig { /** * A provider token used to configure the location upgrade module. * + * 提供者令牌,用于配置 location 升级模块。 + * * @publicApi */ export const LOCATION_UPGRADE_CONFIGURATION = @@ -56,8 +75,12 @@ const APP_BASE_HREF_RESOLVED = new InjectionToken('APP_BASE_HREF_RESOLVE /** * `NgModule` used for providing and configuring Angular's Unified Location Service for upgrading. * + * `NgModule` 用于提供和配置 Angular 的统一 location 服务以进行升级。 + * * @see [Using the Unified Angular Location Service](guide/upgrade#using-the-unified-angular-location-service) * + * [使用统一的 Angular location 服务](guide/upgrade#using-the-unified-angular-location-service) + * * @publicApi */ @NgModule({imports: [CommonModule]}) diff --git a/packages/common/upgrade/src/params.ts b/packages/common/upgrade/src/params.ts index c832d619ff..5e4a9ebb66 100644 --- a/packages/common/upgrade/src/params.ts +++ b/packages/common/upgrade/src/params.ts @@ -9,55 +9,92 @@ /** * A codec for encoding and decoding URL parts. * + * 用于编码和解码 URL 部分的编解码器。 + * * @publicApi **/ export abstract class UrlCodec { /** * Encodes the path from the provided string * + * 解码所提供的字符串的路径 + * * @param path The path string + * + * 路径字符串 + * */ abstract encodePath(path: string): string; /** * Decodes the path from the provided string * + * 解码所提供的字符串的路径 + * * @param path The path string + * + * 路径字符串 + * */ abstract decodePath(path: string): string; /** * Encodes the search string from the provided string or object * + * 从所提供的字符串或对象中编码搜索字符串 + * * @param path The path string or object + * + * 路径字符串或对象 + * */ abstract encodeSearch(search: string|{[k: string]: unknown}): string; /** * Decodes the search objects from the provided string * + * 从所提供的字符串中解码搜索对象 + * * @param path The path string + * + * 路径字符串 + * */ abstract decodeSearch(search: string): {[k: string]: unknown}; /** * Encodes the hash from the provided string * + * 对所提供的字符串中的哈希进行编码 + * * @param path The hash string + * + * 哈希字符串 + * */ abstract encodeHash(hash: string): string; /** * Decodes the hash from the provided string * + * 从所提供的字符串中解码哈希 + * * @param path The hash string + * + * 哈希字符串 + * */ abstract decodeHash(hash: string): string; /** * Normalizes the URL from the provided string * + * 从所提供的字符串中标准化 URL + * * @param path The URL string + * + * URL 字符串 + * */ abstract normalize(href: string): string; @@ -65,26 +102,57 @@ export abstract class UrlCodec { /** * Normalizes the URL from the provided string, search, hash, and base URL parameters * + * 根据所提供的字符串、搜索、哈希和基本 URL 参数标准化 URL + * * @param path The URL path + * + * 网址路径 + * * @param search The search object + * + * 搜索对象 + * * @param hash The has string + * + * 哈希字符串 + * * @param baseUrl The base URL for the URL + * + * 此 URL 的基本 URL + * */ abstract normalize(path: string, search: {[k: string]: unknown}, hash: string, baseUrl?: string): string; /** * Checks whether the two strings are equal + * + * 检查两个字符串是否相等 + * * @param valA First string for comparison + * + * 要比较的第一个字符串 + * * @param valB Second string for comparison + * + * 要比较的第二个字符串 + * */ abstract areEqual(valA: string, valB: string): boolean; /** * Parses the URL string based on the base URL * + * 根据基本 URL 解析 URL 字符串 + * * @param url The full URL string + * + * 完整的 URL 字符串 + * * @param base The base for the URL + * + * URL 的 base 部分 + * */ abstract parse(url: string, base?: string): { href: string, @@ -102,6 +170,8 @@ export abstract class UrlCodec { * A `UrlCodec` that uses logic from AngularJS to serialize and parse URLs * and URL parameters. * + * 一个 `UrlCodec`,它使用 AngularJS 中的逻辑来序列化和解析 URL 和 URL 参数。 + * * @publicApi */ export class AngularJSUrlCodec implements UrlCodec { diff --git a/packages/common/upgrade/test/upgrade_location_test_module.ts b/packages/common/upgrade/test/upgrade_location_test_module.ts index f154080033..1598f0c587 100644 --- a/packages/common/upgrade/test/upgrade_location_test_module.ts +++ b/packages/common/upgrade/test/upgrade_location_test_module.ts @@ -28,6 +28,8 @@ export interface LocationUpgradeTestingConfig { * * Is used in DI to configure the router. * + * 用于在 DI 中配置路由器。 + * * @publicApi */ export const LOC_UPGRADE_TEST_CONFIG = diff --git a/packages/core/src/application_init.ts b/packages/core/src/application_init.ts index d464573b44..4bf5fd25bd 100644 --- a/packages/core/src/application_init.ts +++ b/packages/core/src/application_init.ts @@ -15,15 +15,21 @@ import {noop} from './util/noop'; * A [DI token](guide/glossary#di-token "DI token definition") that you can use to provide * one or more initialization functions. * + * 可用于提供一个或多个初始化功能的 [DI 令牌。](guide/glossary#di-token "DI 令牌定义") + * * The provided functions are injected at application startup and executed during * app initialization. If any of these functions returns a Promise, initialization * does not complete until the Promise is resolved. * + * 所提供的函数是在应用程序启动时注入的,并在应用程序初始化期间执行。如果这些函数中的任何一个返回 Promise,则直到 Promise 被解析之前,初始化都不会完成。 + * * You can, for example, create a factory function that loads language data * or an external configuration, and provide that function to the `APP_INITIALIZER` token. * The function is executed during the application bootstrap process, * and the needed data is available on startup. * + * 例如,你可以创建一个工厂函数来加载语言数据或外部配置,并将该函数提供给 `APP_INITIALIZER` 令牌。该功能在应用程序引导过程中执行,并且所需的数据在启动时可用。 + * * @see `ApplicationInitStatus` * * @publicApi @@ -33,6 +39,8 @@ export const APP_INITIALIZER = new InjectionToken void>>('Applicatio /** * A class that reflects the state of running {@link APP_INITIALIZER} functions. * + * 反映正在运行的 {@link APP_INITIALIZER} 函数状态的类。 + * * @publicApi */ @Injectable() diff --git a/packages/core/src/application_module.ts b/packages/core/src/application_module.ts index b5eedcede5..77f36a1efe 100644 --- a/packages/core/src/application_module.ts +++ b/packages/core/src/application_module.ts @@ -124,9 +124,13 @@ export function zoneSchedulerFactory(ngZone: NgZone): (fn: () => void) => void { * providers of `@angular/core` dependencies that `ApplicationRef` needs * to bootstrap components. * + * 为应用配置根注入器,它带有 `ApplicationRef` 在引导组件时所需的来自 `@angular/core` 的提供者。 + * * Re-exported by `BrowserModule`, which is included automatically in the root * `AppModule` when you create a new app with the CLI `new` command. * + * 由 `BrowserModule` 重新导出,当你使用 CLI `new` 命令创建新应用时,它会自动包含在根 `AppModule` 中。 + * * @publicApi */ @NgModule({providers: APPLICATION_MODULE_PROVIDERS}) diff --git a/packages/core/src/application_ref.ts b/packages/core/src/application_ref.ts index cdff12ceef..eda196b95f 100644 --- a/packages/core/src/application_ref.ts +++ b/packages/core/src/application_ref.ts @@ -130,6 +130,8 @@ export const ALLOW_MULTIPLE_PLATFORMS = new InjectionToken('AllowMultip /** * A token for third-party components that can register themselves with NgProbe. * + * 本令牌可以在 NgProbe 中注册自己的第三方组件。 + * * @publicApi */ export class NgProbeToken { @@ -140,6 +142,8 @@ export class NgProbeToken { * Creates a platform. * Platforms must be created on launch using this function. * + * 创建一个平台。必须使用此函数在启动时创建平台。 + * * @publicApi */ export function createPlatform(injector: Injector): PlatformRef { @@ -158,12 +162,23 @@ export function createPlatform(injector: Injector): PlatformRef { /** * Creates a factory for a platform. Can be used to provide or override `Providers` specific to * your applciation's runtime needs, such as `PLATFORM_INITIALIZER` and `PLATFORM_ID`. + * + * 为平台创建工厂。可用于提供或覆盖针对你的应用程序的运行时需求的 `Providers`,比如 `PLATFORM_INITIALIZER` 和 `PLATFORM_ID` 。 + * * @param parentPlatformFactory Another platform factory to modify. Allows you to compose factories * to build up configurations that might be required by different libraries or parts of the * application. + * + * 要修改的另一个平台工厂。允许你组合多个工厂来构建一些配置,其它库或应用程序的其它部分可能需要的它们。 + * * @param name Identifies the new platform factory. + * + * 标识新的平台工厂。 + * * @param providers A set of dependency providers for platforms created with the new factory. * + * 使用新工厂创建的平台的一组依赖项提供者。 + * * @publicApi */ export function createPlatformFactory( @@ -193,6 +208,8 @@ export function createPlatformFactory( /** * Checks that there is currently a platform that contains the given token as a provider. * + * 检查当前是否存在以给定令牌为提供者的平台。 + * * @publicApi */ export function assertPlatform(requiredToken: any): PlatformRef { @@ -214,6 +231,8 @@ export function assertPlatform(requiredToken: any): PlatformRef { * Destroys the current Angular platform and all Angular applications on the page. * Destroys all modules and listeners registered with the platform. * + * 销毁页面上的当前 Angular 平台和所有 Angular 应用程序。销毁在平台上注册的所有模块和监听器。 + * * @publicApi */ export function destroyPlatform(): void { @@ -225,6 +244,8 @@ export function destroyPlatform(): void { /** * Returns the current platform. * + * 返回当前平台。 + * * @publicApi */ export function getPlatform(): PlatformRef|null { @@ -294,6 +315,8 @@ export interface BootstrapOptions { * A page's platform is initialized implicitly when a platform is created using a platform * factory such as `PlatformBrowser`, or explicitly by calling the `createPlatform()` function. * + * Angular 平台是 Angular 在网页上的入口点。每个页面只有一个平台。页面上运行的每个 Angular 应用程序所共有的服务(例如反射)都在其范围内绑定。当使用 `PlatformBrowser` 这样的平台工厂创建平台时,将隐式初始化此页面的平台;也可以通过调用 `createPlatform()` 函数来显式初始化此页面的平台。 + * * @publicApi */ @Injectable() @@ -308,10 +331,14 @@ export class PlatformRef { /** * Creates an instance of an `@NgModule` for the given platform for offline compilation. * + * 为给定的平台创建 `@NgModule` 的实例,以进行离线编译。 + * * @usageNotes * * The following example creates the NgModule for a browser platform. * + * 以下示例为浏览器平台创建 NgModule。 + * * ```typescript * my_module.ts: * @@ -375,9 +402,14 @@ export class PlatformRef { /** * Creates an instance of an `@NgModule` for a given platform using the given runtime compiler. * + * 使用给定的运行时编译器为给定的平台创建 `@NgModule` 的实例。 + * * @usageNotes + * * ### Simple Example * + * ### 简单的例子 + * * ```typescript * @NgModule({ * imports: [BrowserModule] @@ -416,6 +448,9 @@ export class PlatformRef { /** * Registers a listener to be called when the platform is destroyed. + * + * 注册销毁平台时要调用的监听器。 + * */ onDestroy(callback: () => void): void { this._destroyListeners.push(callback); @@ -424,6 +459,9 @@ export class PlatformRef { /** * Retrieves the platform {@link Injector}, which is the parent injector for * every Angular application on the page and provides singleton providers. + * + * 检索平台 {@link Injector},该平台是页面上每个 Angular 应用程序的父注入器,并提供单例提供者。 + * */ get injector(): Injector { return this._injector; @@ -432,6 +470,9 @@ export class PlatformRef { /** * Destroys the current Angular platform and all Angular applications on the page. * Destroys all modules and listeners registered with the platform. + * + * 销毁页面上的当前 Angular 平台和所有 Angular 应用程序。销毁在平台上注册的所有模块和监听器。 + * */ destroy() { if (this._destroyed) { @@ -496,6 +537,8 @@ function optionsReducer(dst: any, objs: T|T[]): T { /** * A reference to an Angular application running on a page. * + * 对页面上运行的 Angular 应用程序的引用。 + * * @usageNotes * * {@a is-stable-examples} @@ -598,18 +641,29 @@ export class ApplicationRef { /** * Get a list of component types registered to this application. * This list is populated even before the component is created. + * + * 获取注册到该应用程序的组件类型的列表。在创建组件之前,会填充此列表。 + * */ public readonly componentTypes: Type[] = []; /** * Get a list of components registered to this application. + * + * 获取已注册到该应用中的组件的列表。 + * */ public readonly components: ComponentRef[] = []; /** * Returns an Observable that indicates when the application is stable or unstable. * + * 返回一个 Observable,指示应用程序何时变得稳定或不稳定。 + * * @see [Usage notes](#is-stable-examples) for examples and caveats when using this API. + * + * [用法说明](#is-stable-examples)的例子和使用此 API 时的注意事项。 + * */ // TODO(issue/24571): remove '!'. public readonly isStable!: Observable; @@ -682,17 +736,29 @@ export class ApplicationRef { /** * Bootstrap a new component at the root level of the application. * + * 在应用程序的根级引导新组件。 + * * @usageNotes + * * ### Bootstrap process * + * ### 引导过程 + * * When bootstrapping a new root component into an application, Angular mounts the * specified application component onto DOM elements identified by the componentType's * selector and kicks off automatic change detection to finish initializing the component. * + * 将新的根组件引导到应用程序时,Angular 将指定的应用程序组件安装到由 componentType 的选择器标识的 DOM 元素上,并启动自动变更检测以完成组件的初始化。 + * * Optionally, a component can be mounted onto a DOM element that does not match the * componentType's selector. * + * (可选)可以将组件安装到与 componentType 的选择器不匹配的 DOM 元素上。 + * * ### Example + * + * ### 例子 + * * {@example core/ts/platform/platform.ts region='longform'} */ bootstrap(componentOrFactory: ComponentFactory|Type, rootSelectorOrNode?: string|any): @@ -736,12 +802,17 @@ export class ApplicationRef { /** * Invoke this method to explicitly process change detection and its side-effects. * + * 调用此方法可以显式处理变更检测及其副作用。 + * * In development mode, `tick()` also performs a second change detection cycle to ensure that no * further changes are detected. If additional changes are picked up during this second cycle, * bindings in the app have side-effects that cannot be resolved in a single change detection * pass. * In this case, Angular throws an error, since an Angular application can only have one change * detection pass during which all change detection must complete. + * + * 在开发模式下,`tick()` 还会执行第二个变更检测周期,以确保没有检测到其他更改。如果在第二个周期内获取了其他更改,则应用程序中的绑定就会产生副作用,这些副作用无法通过一次变更检测过程解决。在这种情况下,Angular 就会引发错误,因为 Angular 应用程序只能进行一次变更检测遍历,在此过程中必须完成所有变更检测。 + * */ tick(): void { if (this._runningTick) { @@ -770,6 +841,9 @@ export class ApplicationRef { * Attaches a view so that it will be dirty checked. * The view will be automatically detached when it is destroyed. * This will throw if the view is already attached to a ViewContainer. + * + * 附加视图,以便对其进行脏检查。视图销毁后将自动分离。如果视图已附加到 ViewContainer,则会抛出此错误。 + * */ attachView(viewRef: ViewRef): void { const view = (viewRef as InternalViewRef); @@ -779,6 +853,9 @@ export class ApplicationRef { /** * Detaches a view from dirty checking again. + * + * 再次从脏检查中分离视图。 + * */ detachView(viewRef: ViewRef): void { const view = (viewRef as InternalViewRef); @@ -809,6 +886,9 @@ export class ApplicationRef { /** * Returns the number of attached views. + * + * 返回已附加视图的数量。 + * */ get viewCount() { return this._views.length; diff --git a/packages/core/src/application_tokens.ts b/packages/core/src/application_tokens.ts index 659fa27efe..670f2ffdfa 100644 --- a/packages/core/src/application_tokens.ts +++ b/packages/core/src/application_tokens.ts @@ -15,10 +15,14 @@ import {ComponentRef} from './linker/component_factory'; * primarily for prefixing application attributes and CSS styles when * {@link ViewEncapsulation#Emulated ViewEncapsulation.Emulated} is being used. * + * 表示唯一字符串 ID 的 [DI 令牌](guide/glossary#di-token "DI 令牌定义"),主要用于在使用 {@link ViewEncapsulation#Emulated ViewEncapsulation.Emulated} 时为应用程序属性和 CSS 样式添加前缀。 + * * BY default, the value is randomly generated and assigned to the application by Angular. * To provide a custom ID value, use a DI provider to configure * the root {@link Injector} that uses this token. * + * 默认情况下,该值是随机生成的,并且由 Angular 赋值给此应用。要提供一个自定义的 ID 值,可以使用一个 DI 提供者,根 {@link Injector} 会使用此令牌。 + * * @publicApi */ export const APP_ID = new InjectionToken('AppId'); @@ -29,6 +33,9 @@ export function _appIdRandomProviderFactory() { /** * Providers that generate a random `APP_ID_TOKEN`. + * + * 生成随机 `APP_ID_TOKEN` 的提供者。 + * * @publicApi */ export const APP_ID_RANDOM_PROVIDER = { @@ -43,12 +50,18 @@ function _randomChar(): string { /** * A function that is executed when a platform is initialized. + * + * 平台初始化时执行的函数。 + * * @publicApi */ export const PLATFORM_INITIALIZER = new InjectionToken void>>('Platform Initializer'); /** * A token that indicates an opaque platform ID. + * + * 标识不透明平台 ID 的令牌。 + * * @publicApi */ export const PLATFORM_ID = new InjectionToken('Platform ID'); @@ -57,8 +70,12 @@ export const PLATFORM_ID = new InjectionToken('Platform ID'); * A [DI token](guide/glossary#di-token "DI token definition") that provides a set of callbacks to * be called for every component that is bootstrapped. * + * 一个 [DI 令牌](guide/glossary#di-token "DI 令牌定义"),该令牌提供了一组针对每个要引导的组件调用的回调。 + * * Each callback must take a `ComponentRef` instance and return nothing. * + * 每个回调都必须接受 `ComponentRef` 实例,并且不返回任何内容。 + * * `(componentRef: ComponentRef) => void` * * @publicApi @@ -69,6 +86,9 @@ export const APP_BOOTSTRAP_LISTENER = /** * A [DI token](guide/glossary#di-token "DI token definition") that indicates the root directory of * the application + * + * 一个 [DI 令牌](guide/glossary#di-token "DI 令牌定义"),指示应用程序的根目录 + * * @publicApi */ export const PACKAGE_ROOT_URL = new InjectionToken('Application Packages Root URL'); diff --git a/packages/core/src/change_detection/change_detection_util.ts b/packages/core/src/change_detection/change_detection_util.ts index 3e5f06f303..05bd0e7d78 100644 --- a/packages/core/src/change_detection/change_detection_util.ts +++ b/packages/core/src/change_detection/change_detection_util.ts @@ -50,6 +50,9 @@ export function devModeEqual(a: any, b: any): boolean { * * @publicApi * @deprecated from v10 stop using. (No replacement, deemed unnecessary.) + * + * 从 v10 开始停止使用。 (无替代品,没必要。) + * */ export class WrappedValue { /** @deprecated from 5.3, use `unwrap()` instead - will switch to protected diff --git a/packages/core/src/change_detection/change_detector_ref.ts b/packages/core/src/change_detection/change_detector_ref.ts index 8cf769d048..bef6be8aeb 100644 --- a/packages/core/src/change_detection/change_detector_ref.ts +++ b/packages/core/src/change_detection/change_detector_ref.ts @@ -25,14 +25,20 @@ const SWITCH_CHANGE_DETECTOR_REF_FACTORY: typeof injectChangeDetectorRef = * Use the methods to add and remove views from the tree, initiate change-detection, * and explicitly mark views as _dirty_, meaning that they have changed and need to be re-rendered. * - * @see [Using change detection hooks](guide/lifecycle-hooks#using-change-detection-hooks) - * @see [Defining custom change detection](guide/lifecycle-hooks#defining-custom-change-detection) - * * Angular 各种视图的基础类,提供变更检测功能。 * 变更检测树会收集要检查的所有视图。 * 使用这些方法从树中添加或移除视图、初始化变更检测并显式地把这些视图标记为*脏的*,意思是它们变了、需要重新渲染。 * - * @usageNotes + * @see [Using change detection hooks](guide/lifecycle-hooks#using-change-detection-hooks) + * + * [使用变更检测钩子](guide/lifecycle-hooks#using-change-detection-hooks) + * + * @see [Defining custom change detection](guide/lifecycle-hooks#defining-custom-change-detection) + * + * [定义自定义变更检测](guide/lifecycle-hooks#defining-custom-change-detection) + * + * + *@usageNotes * * The following examples demonstrate how to modify default change-detection behavior * to perform explicit detection when needed. @@ -171,6 +177,8 @@ export abstract class ChangeDetectorRef { /** * This marker is need so that the JIT compiler can correctly identify this class as special. * + * 使用此标记,以便 JIT 编译器可以正确地将此类标识为特殊类。 + * * @internal * @nocollapse */ @@ -208,4 +216,4 @@ function createViewRef(tNode: TNode, lView: LView, isPipe: boolean): ChangeDetec return new R3_ViewRef(hostComponentView, lView); } return null!; -} \ No newline at end of file +} diff --git a/packages/core/src/change_detection/constants.ts b/packages/core/src/change_detection/constants.ts index bc81f02f62..840ab60efc 100644 --- a/packages/core/src/change_detection/constants.ts +++ b/packages/core/src/change_detection/constants.ts @@ -11,8 +11,12 @@ * The strategy that the default change detector uses to detect changes. * When set, takes effect the next time change detection is triggered. * + * 默认变更检测器用来检测更改的策略。设置后,将在下次触发变更检测时生效。 + * * @see {@link ChangeDetectorRef#usage-notes Change detection usage} * + * {@link ChangeDetectorRef#usage-notes 变更检测的用法} + * * @publicApi */ export enum ChangeDetectionStrategy { @@ -21,12 +25,18 @@ export enum ChangeDetectionStrategy { * until reactivated by setting the strategy to `Default` (`CheckAlways`). * Change detection can still be explicitly invoked. * This strategy applies to all child directives and cannot be overridden. + * + * 使用 `CheckOnce` 策略,这意味着把此策略设置为 `Default`( `CheckAlways` )将禁用自动变更检测,直到重新激活。变更检测仍然可以显式调用。此策略适用于所有子指令,并且不能被覆盖。 + * */ OnPush = 0, /** * Use the default `CheckAlways` strategy, in which change detection is automatic until * explicitly deactivated. + * + * 使用默认的 `CheckAlways` 策略,在该策略中,变更检测将自动执行,直到显式停用为止。 + * */ Default = 1, } diff --git a/packages/core/src/change_detection/differs/default_iterable_differ.ts b/packages/core/src/change_detection/differs/default_iterable_differ.ts index 91717994cc..bda5af58de 100644 --- a/packages/core/src/change_detection/differs/default_iterable_differ.ts +++ b/packages/core/src/change_detection/differs/default_iterable_differ.ts @@ -27,6 +27,9 @@ const trackByIdentity = (index: number, item: any) => item; /** * @deprecated v4.0.0 - Should not be part of public API. + * + * v4.0.0-不应成为公共 API 的一部分。 + * * @publicApi */ export class DefaultIterableDiffer implements IterableDiffer, IterableChanges { @@ -231,6 +234,8 @@ export class DefaultIterableDiffer implements IterableDiffer, IterableChan * Set the previousIndexes of moved and added items to their currentIndexes * Reset the list of additions, moves and removals * + * 重置更改对象的状态以便不显示任何更改。这意味着将 previousKey 设置为 currentKey,并清除所有队列(添加、移动、移除)。将已移动和已添加条目的 previousIndexes 设置为其 currentIndexes。重置包含添加、移动和删除的列表 + * * @internal */ _reset() { @@ -261,11 +266,21 @@ export class DefaultIterableDiffer implements IterableDiffer, IterableChan /** * This is the core function which handles differences between collections. * + * 这是处理集合之间差异的核心函数。 + * * - `record` is the record which we saw at this position last time. If null then it is a new * item. + * + * `record` 是我们上次在此位置看到的记录。如果为 null,则为新条目。 + * * - `item` is the current item in the collection + * + * `item` 是集合中的当前条目 + * * - `index` is the position of the item in the collection * + * `index` 是条目在集合中的位置 + * * @internal */ _mismatch(record: IterableChangeRecord_|null, item: V, itemTrackBy: any, index: number): @@ -310,20 +325,51 @@ export class DefaultIterableDiffer implements IterableDiffer, IterableChan /** * This check is only needed if an array contains duplicates. (Short circuit of nothing dirty) * + * 仅当数组包含重复项时才需要进行此检查。 (不脏时跳过) + * * Use case: `[a, a]` => `[b, a, a]` * + * 用例: `[a, a]` => `[b, a, a]` + * * If we did not have this check then the insertion of `b` would: - * 1) evict first `a` - * 2) insert `b` at `0` index. - * 3) leave `a` at index `1` as is. <-- this is wrong! - * 3) reinsert `a` at index 2. <-- this is wrong! + * + * 如果我们不做这项检查,则插入 `b` 时会: + * + * 1. evict first `a` + * + * 移出第一个 `a` + * + * 1. insert `b` at `0` index. + * + * 把 `b` 插入在 `0` 号索引处。 + * + * 1. leave `a` at index `1` as is. <-- this is wrong! + * + * 把 `a` 留在现在的 `1` 号索引处。<-- 这是错的! + * + * 1. reinsert `a` at index 2. <-- this is wrong! + * + * 重新把 `a` 插入在 `2` 号索引处。 <-- 这是错的! * * The correct behavior is: - * 1) evict first `a` - * 2) insert `b` at `0` index. - * 3) reinsert `a` at index 1. - * 3) move `a` at from `1` to `2`. * + * 正确的行为是: + * + * 1. evict first `a` + * + * 移出第一个 `a` + * + * 1. insert `b` at `0` index. + * + * 把 `b` 插入在 `0` 号索引处。 + * + * 1. reinsert `a` at index 1. + * + * 把 `a` 插入在 `1` 号索引处。 + * + * 1. move `a` at from `1` to `2`. + * + * 把 `a` 从 `1` 号位移到 `2` 号位。 * * Double check that we have not evicted a duplicate item. We need to check if the item type may * have already been removed: @@ -332,6 +378,8 @@ export class DefaultIterableDiffer implements IterableDiffer, IterableChan * better way to think of it is as insert of 'b' rather then switch 'a' with 'b' and then add 'a' * at the end. * + * 再次确认我们没有移出重复的条目。我们需要检查此条目类型是否已被删除:插入 b 将移出第一个 “a”。如果我们现在不重新插入,它将重新在最后插入。这将表现为两个 “a” 调换了位置。这是不正确的,因为更好的方法是插入 “b”,而不是将 “a” 和 “b” 互换,然后在末尾添加 “a”。 + * * @internal */ _verifyReinsertion(record: IterableChangeRecord_, item: V, itemTrackBy: any, index: number): @@ -350,7 +398,11 @@ export class DefaultIterableDiffer implements IterableDiffer, IterableChan /** * Get rid of any excess {@link IterableChangeRecord_}s from the previous collection * - * - `record` The first excess {@link IterableChangeRecord_}. + * 摆脱上一个集合中任何多余的 {@link IterableChangeRecord_} + * + * - `record` The first excess {@link IterableChangeRecord\_}. + * + * `record` 是指第一个多余的{@link IterableChangeRecord\_}。 * * @internal */ diff --git a/packages/core/src/change_detection/differs/iterable_differs.ts b/packages/core/src/change_detection/differs/iterable_differs.ts index b9192746be..d6f8ea136f 100644 --- a/packages/core/src/change_detection/differs/iterable_differs.ts +++ b/packages/core/src/change_detection/differs/iterable_differs.ts @@ -16,6 +16,8 @@ import {DefaultIterableDifferFactory} from '../differs/default_iterable_differ'; /** * A type describing supported iterable types. * + * 描述受支持的可迭代类型的类型。 + * * @publicApi */ export type NgIterable = Array|Iterable; @@ -24,15 +26,25 @@ export type NgIterable = Array|Iterable; * A strategy for tracking changes over time to an iterable. Used by {@link NgForOf} to * respond to changes in an iterable by effecting equivalent changes in the DOM. * + * 用来跟踪一个迭代内的更改的策略。{@link NgForOf} 使用它通过对 DOM 进行等效更改来响应此迭代内的更改。 + * * @publicApi */ export interface IterableDiffer { /** * Compute a difference between the previous state and the new `object` state. * + * 计算先前状态和新 `object` 状态之间的差异。 + * * @param object containing the new value. + * + * 包含新值。 + * * @returns an object describing the difference. The return value is only valid until the next * `diff()` invocation. + * + * 描述差异的对象。返回值仅在下一次 `diff()` 调用之前有效。 + * */ diff(object: NgIterable|undefined|null): IterableChanges|null; } @@ -41,12 +53,17 @@ export interface IterableDiffer { * An object describing the changes in the `Iterable` collection since last time * `IterableDiffer#diff()` was invoked. * + * 本对象描述自上次调用 `IterableDiffer#diff()` 以来 `Iterable` 集合中的变更。 + * * @publicApi */ export interface IterableChanges { /** * Iterate over all changes. `IterableChangeRecord` will contain information about changes * to each item. + * + * 遍历所有更改。`IterableChangeRecord` 将包含有关每个条目更改的信息。 + * */ forEachItem(fn: (record: IterableChangeRecord) => void): void; @@ -54,17 +71,30 @@ export interface IterableChanges { * Iterate over a set of operations which when applied to the original `Iterable` will produce the * new `Iterable`. * + * 遍历一组操作,将这些操作应用于原始 `Iterable`,将产生新的 `Iterable` 。 + * * NOTE: These are not necessarily the actual operations which were applied to the original * `Iterable`, rather these are a set of computed operations which may not be the same as the * ones applied. * + * 注意:这些不一定是应用于原始 `Iterable` 的实际操作,而是这些计算的操作集合,可能与所应用的操作不同。 + * * @param record A change which needs to be applied + * + * 需要应用的更改 + * * @param previousIndex The `IterableChangeRecord#previousIndex` of the `record` refers to the * original `Iterable` location, where as `previousIndex` refers to the transient location * of the item, after applying the operations up to this point. + * + * 此 `record` 的 `IterableChangeRecord#previousIndex` 是指原来 `Iterable` 中的位置,这个 `previousIndex` 是指应用此操作之后条目的瞬时位置。 + * * @param currentIndex The `IterableChangeRecord#currentIndex` of the `record` refers to the * original `Iterable` location, where as `currentIndex` refers to the transient location * of the item, after applying the operations up to this point. + * + * 此 `record` 的 `IterableChangeRecord#currentIndex` 是指原来 `Iterable` 中的位置,这个 `currentIndex` 是指应用此操作之后条目的瞬时位置。 + * */ forEachOperation( fn: @@ -74,21 +104,42 @@ export interface IterableChanges { /** * Iterate over changes in the order of original `Iterable` showing where the original items * have moved. + * + * 按原始 `Iterable` 中的顺序遍历这些变更,以找出原始条目移动到的位置。 + * */ forEachPreviousItem(fn: (record: IterableChangeRecord) => void): void; - /** Iterate over all added items. */ + /** + * Iterate over all added items. + * + * 遍历所有添加的条目。 + * + */ forEachAddedItem(fn: (record: IterableChangeRecord) => void): void; - /** Iterate over all moved items. */ + /** + * Iterate over all moved items. + * + * 遍历所有移动过的条目。 + * + */ forEachMovedItem(fn: (record: IterableChangeRecord) => void): void; - /** Iterate over all removed items. */ + /** + * Iterate over all removed items. + * + * 遍历所有已删除的条目。 + * + */ forEachRemovedItem(fn: (record: IterableChangeRecord) => void): void; /** * Iterate over all items which had their identity (as computed by the `TrackByFunction`) * changed. + * + * 遍历所有更改过标识(由 `TrackByFunction` 计算)的条目。 + * */ forEachIdentityChange(fn: (record: IterableChangeRecord) => void): void; } @@ -96,19 +147,41 @@ export interface IterableChanges { /** * Record representing the item change information. * + * 代表条目变更信息的记录。 + * * @publicApi */ export interface IterableChangeRecord { - /** Current index of the item in `Iterable` or null if removed. */ + /** + * Current index of the item in `Iterable` or null if removed. + * + * 此条目在 `Iterable` 中的当前索引,如果已删除则为 null。 + * + */ readonly currentIndex: number|null; - /** Previous index of the item in `Iterable` or null if added. */ + /** + * Previous index of the item in `Iterable` or null if added. + * + * 此条目在 `Iterable` 中以前的索引,如果是新添加的则为 null。 + * + */ readonly previousIndex: number|null; - /** The item. */ + /** + * The item. + * + * 本条目。 + * + */ readonly item: V; - /** Track by identity as computed by the `TrackByFunction`. */ + /** + * Track by identity as computed by the `TrackByFunction`. + * + * 通过 `TrackByFunction` 计算出的标识进行跟踪。 + * + */ readonly trackById: any; } @@ -118,6 +191,8 @@ export interface IterableChangeRecord { * The function takes the iteration index and item ID. * When supplied, Angular tracks changes by the return value of the function. * + * 传给 `NgForOf` 指令的可选函数,该函数定义如何跟踪可迭代对象中条目的更改。该函数接受迭代索引和条目 ID 作为参数。提供后,Angular 将根据函数的返回值的变化进行跟踪。 + * * @publicApi */ export interface TrackByFunction { @@ -127,6 +202,8 @@ export interface TrackByFunction { /** * Provides a factory for {@link IterableDiffer}. * + * 提供 {@link IterableDiffer} 的工厂。 + * * @publicApi */ export interface IterableDifferFactory { @@ -137,6 +214,8 @@ export interface IterableDifferFactory { /** * A repository of different iterable diffing strategies used by NgFor, NgClass, and others. * + * NgFor、NgClass 等使用的不同迭代策略的存储库。 + * * @publicApi */ export class IterableDiffers { @@ -149,6 +228,9 @@ export class IterableDiffers { /** * @deprecated v4.0.0 - Should be private + * + * v4.0.0-应该是私有的 + * */ factories: IterableDifferFactory[]; constructor(factories: IterableDifferFactory[]) { @@ -169,13 +251,20 @@ export class IterableDiffers { * inherited {@link IterableDiffers} instance with the provided factories and return a new * {@link IterableDiffers} instance. * + * 接受一个 {@link IterableDifferFactory} 数组,并返回一个提供者,用于扩展继承的带有提供者工厂的 {@link IterableDiffers} 实例,并返回一个新的 {@link IterableDiffers} 实例。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * The following example shows how to extend an existing list of factories, * which will only be applied to the injector for this component and its children. * This step is all that's required to make a new {@link IterableDiffer} available. * + * 以下示例演示了如何扩展现有工厂列表,该列表仅适用于该组件及其子组件的注入器。这就是使新的 {@link IterableDiffer} 可用的全部步骤。 + * * ``` * @Component({ * viewProviders: [ diff --git a/packages/core/src/change_detection/differs/keyvalue_differs.ts b/packages/core/src/change_detection/differs/keyvalue_differs.ts index 7f9bd89a3d..28ffadf68f 100644 --- a/packages/core/src/change_detection/differs/keyvalue_differs.ts +++ b/packages/core/src/change_detection/differs/keyvalue_differs.ts @@ -13,24 +13,42 @@ import {DefaultKeyValueDifferFactory} from './default_keyvalue_differ'; /** * A differ that tracks changes made to an object over time. * + * 跟踪对象随时间变化的差异。 + * * @publicApi */ export interface KeyValueDiffer { /** * Compute a difference between the previous state and the new `object` state. * + * 计算先前状态和新 `object` 状态之间的差异。 + * * @param object containing the new value. + * + * 包含新值。 + * * @returns an object describing the difference. The return value is only valid until the next * `diff()` invocation. + * + * 描述差异的对象。返回值仅在下一次 `diff()` 调用之前有效。 + * */ diff(object: Map): KeyValueChanges|null; /** * Compute a difference between the previous state and the new `object` state. * + * 计算先前状态和新 `object` 状态之间的差异。 + * * @param object containing the new value. + * + * 包含新值。 + * * @returns an object describing the difference. The return value is only valid until the next * `diff()` invocation. + * + * 描述差异的对象。返回值仅在下一次 `diff()` 调用之前有效。 + * */ diff(object: {[key: string]: V}): KeyValueChanges|null; // TODO(TS2.1): diff(this: KeyValueDiffer, object: Record): @@ -41,33 +59,50 @@ export interface KeyValueDiffer { * An object describing the changes in the `Map` or `{[k:string]: string}` since last time * `KeyValueDiffer#diff()` was invoked. * + * 一个对象,描述自上次调用 `KeyValueDiffer#diff()` 以来的变化的 `Map` 或 `{[k:string]: string}`。 + * * @publicApi */ export interface KeyValueChanges { /** * Iterate over all changes. `KeyValueChangeRecord` will contain information about changes * to each item. + * + * 遍历所有更改。`KeyValueChangeRecord` 将包含有关每个条目更改的信息。 + * */ forEachItem(fn: (r: KeyValueChangeRecord) => void): void; /** * Iterate over changes in the order of original Map showing where the original items * have moved. + * + * 按照原始映射表中的顺序遍历更改,以显示原始条目移动过的位置。 + * */ forEachPreviousItem(fn: (r: KeyValueChangeRecord) => void): void; /** * Iterate over all keys for which values have changed. + * + * 遍历所有更改了值的键名。 + * */ forEachChangedItem(fn: (r: KeyValueChangeRecord) => void): void; /** * Iterate over all added items. + * + * 遍历所有已添加的条目。 + * */ forEachAddedItem(fn: (r: KeyValueChangeRecord) => void): void; /** * Iterate over all removed items. + * + * 遍历所有已删除的条目。 + * */ forEachRemovedItem(fn: (r: KeyValueChangeRecord) => void): void; } @@ -75,21 +110,32 @@ export interface KeyValueChanges { /** * Record representing the item change information. * + * 代表条目变更信息的记录。 + * * @publicApi */ export interface KeyValueChangeRecord { /** * Current key in the Map. + * + * 地图中的当前键名。 + * */ readonly key: K; /** * Current value for the key or `null` if removed. + * + * 键名的当前值;如果已删除,则为 `null` + * */ readonly currentValue: V|null; /** * Previous value for the key or `null` if added. + * + * 键名的先前值;如果是添加的,则为 `null` + * */ readonly previousValue: V|null; } @@ -97,16 +143,24 @@ export interface KeyValueChangeRecord { /** * Provides a factory for {@link KeyValueDiffer}. * + * 提供 {@link KeyValueDiffer} 的工厂。 + * * @publicApi */ export interface KeyValueDifferFactory { /** * Test to see if the differ knows how to diff this kind of object. + * + * 测试看此差分器是否知道如何区分这种对象。 + * */ supports(objects: any): boolean; /** * Create a `KeyValueDiffer`. + * + * 创建一个 `KeyValueDiffer` 。 + * */ create(): KeyValueDiffer; } @@ -114,6 +168,8 @@ export interface KeyValueDifferFactory { /** * A repository of different Map diffing strategies used by NgClass, NgStyle, and others. * + * NgClass、NgStyle 等使用的不同映射表差异策略的存储库。 + * * @publicApi */ export class KeyValueDiffers { @@ -126,6 +182,9 @@ export class KeyValueDiffers { /** * @deprecated v4.0.0 - Should be private. + * + * v4.0.0-应该是私有的。 + * */ factories: KeyValueDifferFactory[]; @@ -146,13 +205,20 @@ export class KeyValueDiffers { * inherited {@link KeyValueDiffers} instance with the provided factories and return a new * {@link KeyValueDiffers} instance. * + * 接受 {@link KeyValueDifferFactory} 的数组,并返回一个提供者,用于使用提供的工厂扩展所继承的 {@link KeyValueDiffers} 实例,并返回一个新的 {@link KeyValueDiffers} 实例。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * The following example shows how to extend an existing list of factories, * which will only be applied to the injector for this component and its children. * This step is all that's required to make a new {@link KeyValueDiffer} available. * + * 以下示例显示如何扩展现有工厂列表,该列表仅适用于该组件及其子组件的注入器。这是使新的{@link KeyValueDiffer}可用的全部步骤。 + * * ``` * @Component({ * viewProviders: [ diff --git a/packages/core/src/debug/debug_node.ts b/packages/core/src/debug/debug_node.ts index 1fb53711a0..7bd555df8b 100644 --- a/packages/core/src/debug/debug_node.ts +++ b/packages/core/src/debug/debug_node.ts @@ -776,6 +776,8 @@ export function removeDebugNodeFromIndex(node: DebugNode) { * A boolean-valued function over a value, possibly including context information * regarding that value's position in an array. * + * 根据参数值返回布尔值的函数,可能包括该值在数组中位置的上下文信息。 + * * @publicApi */ export interface Predicate { diff --git a/packages/core/src/di/forward_ref.ts b/packages/core/src/di/forward_ref.ts index 80250986e0..7cfce888c1 100644 --- a/packages/core/src/di/forward_ref.ts +++ b/packages/core/src/di/forward_ref.ts @@ -15,9 +15,14 @@ import {stringify} from '../util/stringify'; /** * An interface that a function passed into {@link forwardRef} has to implement. * + * 要传给 {@link forwardRef} 的函数时必须实现的接口。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * {@example core/di/ts/forward_ref/forward_ref_spec.ts region='forward_ref_fn'} * @publicApi */ @@ -30,12 +35,20 @@ const __forward_ref__ = getClosureSafeProperty({__forward_ref__: getClosureSafeP /** * Allows to refer to references which are not yet defined. * + * 允许引用尚未定义的引用。 + * * For instance, `forwardRef` is used when the `token` which we need to refer to for the purposes of * DI is declared, but not yet defined. It is also used when the `token` which we use when creating * a query is not yet defined. * + * 例如,当我们需要为所声明的 DI 而引用此 `token`,但尚未定义该令牌时,将使用 `forwardRef`。当我们创建尚未定义的查询的 `token` 时,也会使用它。 + * * @usageNotes + * * ### Example + * + * ### 例子 + * * {@example core/di/ts/forward_ref/forward_ref_spec.ts region='forward_ref'} * @publicApi */ @@ -50,11 +63,18 @@ export function forwardRef(forwardRefFn: ForwardRefFn): Type { /** * Lazily retrieves the reference value from a forwardRef. * + * 从 forwardRef 惰性检索引用值。 + * * Acts as the identity function when given a non-forward-ref value. * + * 给定非前向引用值时,充当标识函数。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * {@example core/di/ts/forward_ref/forward_ref_spec.ts region='resolve_forward_ref'} * * @see `forwardRef` diff --git a/packages/core/src/di/injectable.ts b/packages/core/src/di/injectable.ts index 28871b84b0..bd62d91eff 100644 --- a/packages/core/src/di/injectable.ts +++ b/packages/core/src/di/injectable.ts @@ -19,7 +19,7 @@ import {convertInjectableProviderToFactory} from './util'; /** * Injectable providers used in `@Injectable` decorator. * - * `@Injectable` 装饰器中使用的可注入对象提供商。 + * `@Injectable` 装饰器中使用的可注入对象提供者。 * * @publicApi */ @@ -41,14 +41,21 @@ export interface InjectableDecorator { * 标记性元数据,表示一个类可以由 `Injector` 进行创建。 * * @see [Introduction to Services and DI](guide/architecture-services) + * + * [服务和 DI 简介](guide/architecture-services) + * * @see [Dependency Injection Guide](guide/dependency-injection) * + * [依赖注入指南](guide/dependency-injection) + * * @usageNotes * * Marking a class with `@Injectable` ensures that the compiler * will generate the necessary metadata to create the class's * dependencies when the class is injected. * + * 使用 `@Injectable` 标记一个类可确保编译器将在注入类时生成必要的元数据,以创建类的依赖项。 + * * The following example shows how a service class is properly * marked so that a supporting service can be injected upon creation. * @@ -77,12 +84,22 @@ export interface Injectable { * Determines which injectors will provide the injectable, * by either associating it with an `@NgModule` or other `InjectorType`, * or by specifying that this injectable should be provided in one of the following injectors: + * + * 通过与 `@NgModule` 或其他 `InjectorType` 关联,或通过指定应在以下注入器之一中提供此可注入对象,来确定将提供该对象的注入器: + * * - 'root' : The application-level injector in most apps. + * + * 'root':在大多数应用程序中是指应用程序级注入器。 + * * - 'platform' : A special singleton platform injector shared by all * applications on the page. + * + * 'platform' :页面上所有应用程序共享的平台注入器的特殊单例。 + * * - 'any' : Provides a unique instance in each lazy loaded module while all eagerly loaded * modules share one instance. * + * 'any':在每个惰性加载的模块中提供一个唯一的实例,而所有急性加载的模块共享一个实例。 */ providedIn?: Type|'root'|'platform'|'any'|null; } diff --git a/packages/core/src/di/injection_token.ts b/packages/core/src/di/injection_token.ts index f8b26f7eab..3239e558a1 100644 --- a/packages/core/src/di/injection_token.ts +++ b/packages/core/src/di/injection_token.ts @@ -14,13 +14,19 @@ import {ɵɵdefineInjectable} from './interface/defs'; /** * Creates a token that can be used in a DI Provider. * + * 创建可用于 DI 提供者的令牌。 + * * Use an `InjectionToken` whenever the type you are injecting is not reified (does not have a * runtime representation) such as when injecting an interface, callable type, array or * parameterized type. * + * 每当你要注入的类型无法确定(没有运行时表示形式)时,例如在注入接口、可调用类型、数组或参数化类型时,都应使用 `InjectionToken`。 + * * `InjectionToken` is parameterized on `T` which is the type of object which will be returned by * the `Injector`. This provides additional level of type safety. * + * `InjectionToken` 在 `T` 上的参数化版本,`T` 是 `Injector` 返回的对象的类型。这提供了更高级别的类型安全性。 + * * ``` * interface MyInterface {...} * var myInterface = injector.get(new InjectionToken('SomeToken')); @@ -33,15 +39,24 @@ import {ɵɵdefineInjectable} from './interface/defs'; * application's root injector. If the factory function, which takes zero arguments, needs to inject * dependencies, it can do so using the `inject` function. See below for an example. * + * 当创建 `InjectionToken` 时,可以选择指定一个工厂函数,该函数返回(可能通过创建)参数化类型 `T` 的默认值。这将使用工厂型提供者设置 `InjectionToken`,就像它是在应用程序的根注入器中显式定义的一样。如果使用需要注入依赖项的零参数工厂函数,则可以使用 `inject` 函数来这样做。参见以下示例。 + * * Additionally, if a `factory` is specified you can also specify the `providedIn` option, which * overrides the above behavior and marks the token as belonging to a particular `@NgModule`. As * mentioned above, `'root'` is the default value for `providedIn`. * + * 此外,如果指定了 `factory`,也可以指定 `providedIn` 选项,它会覆盖上述行为,并把这些令牌标记为属于特定 `@NgModule`。如上所述,`'root'` 是 `providedIn` 的默认值。 + * * @usageNotes + * * ### Basic Example * + * ### 基本范例 + * * ### Plain InjectionToken * + * ### 普通注入令牌 + * * {@example core/di/ts/injector_spec.ts region='InjectionToken'} * * ### Tree-shakable InjectionToken diff --git a/packages/core/src/di/injector.ts b/packages/core/src/di/injector.ts index f4c5a37071..9b691f4c4d 100644 --- a/packages/core/src/di/injector.ts +++ b/packages/core/src/di/injector.ts @@ -38,17 +38,26 @@ export const INJECTOR_IMPL = INJECTOR_IMPL__PRE_R3__; * with [providers](guide/glossary#provider) that associate * dependencies of various types with [injection tokens](guide/glossary#di-token). * + * 具体的注入器会实现此接口。配置有[某些提供者](guide/glossary#provider)的注入器,这些提供者会将各种类型的依赖项与[注入令牌](guide/glossary#di-token)相关联。 + * * @see ["DI Providers"](guide/dependency-injection-providers). + * + * [“DI 提供者”](guide/dependency-injection-providers) 。 + * * @see `StaticProvider` * * @usageNotes * * The following example creates a service injector instance. * + * 以下示例创建一个服务注入器实例。 + * * {@example core/di/ts/provider_spec.ts region='ConstructorProvider'} * * ### Usage example * + * ### 使用范例 + * * {@example core/di/ts/injector_spec.ts region='Injector'} * * `Injector` returns itself when given `Injector` as a token: @@ -63,19 +72,34 @@ export abstract class Injector { /** * Retrieves an instance from the injector based on the provided token. + * + * 根据提供的令牌从注入器中检索实例。 + * * @returns The instance from the injector if defined, otherwise the `notFoundValue`. + * + * 注入器的实例(如果已定义),否则为 `notFoundValue` 。 + * * @throws When the `notFoundValue` is `undefined` or `Injector.THROW_IF_NOT_FOUND`. + * + * 当 `notFoundValue` 为 `undefined` 或 `Injector.THROW_IF_NOT_FOUND` 时。 + * */ abstract get( token: Type|AbstractType|InjectionToken, notFoundValue?: T, flags?: InjectFlags): T; /** * @deprecated from v4.0.0 use Type, AbstractType or InjectionToken + * + * 从 v4.0.0 开始,改用 Type、AbstractType 或 InjectionToken + * * @suppress {duplicate} */ abstract get(token: any, notFoundValue?: any): any; /** * @deprecated from v5 use the new signature Injector.create(options) + * + * 从 v5 开始使用新的签名 Injector.create(options) + * */ static create(providers: StaticProvider[], parent?: Injector): Injector; @@ -83,13 +107,27 @@ export abstract class Injector { * Creates a new injector instance that provides one or more dependencies, * according to a given type or types of `StaticProvider`. * + * 创建一个新的注入器实例,该实例会根据指定的类型或 `StaticProvider` 的类型提供一个或多个依赖项。 + * * @param options An object with the following properties: + * + * 具有以下属性的对象: + * * * `providers`: An array of providers of the [StaticProvider type](api/core/StaticProvider). + * + * `providers` :一组 [StaticProvider 类型](api/core/StaticProvider)的提供者。 + * * * `parent`: (optional) A parent injector. - * * `name`: (optional) A developer-defined identifying name for the new injector. + * + * `parent` :(可选)父注入器。 + * + * - `name`: (optional) A developer-defined identifying name for the new injector. + * + * `name` :(可选)新注入器的开发人员自定义的标识名称。 * * @returns The new injector instance. * + * 新的注入器实例。 */ static create(options: {providers: StaticProvider[], parent?: Injector, name?: string}): Injector; diff --git a/packages/core/src/di/injector_compatibility.ts b/packages/core/src/di/injector_compatibility.ts index 71586aa127..ca81293443 100644 --- a/packages/core/src/di/injector_compatibility.ts +++ b/packages/core/src/di/injector_compatibility.ts @@ -63,13 +63,22 @@ export function injectInjectorOnly( /** * Generated instruction: Injects a token from the currently active injector. * + * 生成的方式:从当前活动的注入器注入令牌。 + * * Must be used in the context of a factory function such as one defined for an * `InjectionToken`. Throws an error if not called from such a context. * + * 必须在工厂函数的上下文中使用,比如为 `InjectionToken` 定义的函数。如果未从这样的上下文中调用,则会引发错误。 + * * (Additional documentation moved to `inject`, as it is the public API, and an alias for this * instruction) * + * (其他文档移到了 `inject` ,因为它是公共 API,并且是此指令的别名) + * * @see inject + * + * 注入 + * * @codeGenApi * @publicApi This instruction has been emitted by ViewEngine for some time and is deployed to npm. */ @@ -108,23 +117,39 @@ Please check that 1) the type for the parameter at index ${ /** * Injects a token from the currently active injector. * + * 从当前活动的注入器中注入令牌。 + * * Must be used in the context of a factory function such as one defined for an * `InjectionToken`. Throws an error if not called from such a context. * + * 必须在工厂函数的上下文中使用,比如为 `InjectionToken` 定义的函数。如果未从这样的上下文中调用,则会引发错误。 + * * Within such a factory function, using this function to request injection of a dependency * is faster and more type-safe than providing an additional array of dependencies * (as has been common with `useFactory` providers). * + * 在这样的工厂函数中,使用此函数来请求注入依赖项比提供额外的依赖项数组(在 `useFactory` 提供者中这很常见)要更快且类型安全性更高。 + * * @param token The injection token for the dependency to be injected. + * + * 用于注入依赖项的注入令牌。 + * * @param flags Optional flags that control how injection is executed. * The flags correspond to injection strategies that can be specified with * parameter decorators `@Host`, `@Self`, `@SkipSef`, and `@Optional`. + * + * 控制执行注入方式的可选标志。这些标志对应于可以使用参数装饰器 `@Host`、`@Self`、`@SkipSef` 和 `@Optional` 指定的注入策略。 + * * @returns True if injection is successful, null otherwise. * + * 如果注入成功,则为 true,否则为 null。 + * * @usageNotes * * ### Example * + * ### 例子 + * * {@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'} * * @publicApi diff --git a/packages/core/src/di/injector_token.ts b/packages/core/src/di/injector_token.ts index b84fc4a261..a6bca8392c 100644 --- a/packages/core/src/di/injector_token.ts +++ b/packages/core/src/di/injector_token.ts @@ -15,9 +15,13 @@ import {InjectorMarkers} from './injector_marker'; /** * An InjectionToken that gets the current `Injector` for `createInjector()`-style injectors. * + * 一个 InjectionToken,用于获取当前 `Injector` 的 `createInjector()` 式的注入器。 + * * Requesting this token instead of `Injector` allows `StaticInjector` to be tree-shaken from a * project. * + * 请求此令牌而不是 `Injector` 可使 `StaticInjector` 能在项目中摇树优化掉。 + * * @publicApi */ export const INJECTOR = new InjectionToken( diff --git a/packages/core/src/di/interface/defs.ts b/packages/core/src/di/interface/defs.ts index c3ecb5ecfe..fbccd784f0 100644 --- a/packages/core/src/di/interface/defs.ts +++ b/packages/core/src/di/interface/defs.ts @@ -15,13 +15,19 @@ import {ClassProvider, ConstructorProvider, ExistingProvider, FactoryProvider, S /** * Information about how a type or `InjectionToken` interfaces with the DI system. * + * 有关类型或 `InjectionToken` 如何接入 DI 体系的接口信息。 + * * At a minimum, this includes a `factory` which defines how to create the given type `T`, possibly * requesting injection of other types if necessary. * + * 至少,这要包括一个 `factory` ,该工厂定义如何创建给定类型 `T` ,如有必要,可能会请求注入其他类型。 + * * Optionally, a `providedIn` parameter specifies that the given type belongs to a particular * `InjectorDef`, `NgModule`, or a special scope (e.g. `'root'`). A value of `null` indicates * that the injectable does not belong to any scope. * + * 可选的参数 `providedIn` 规定给定的类型属于某个特定的 `InjectorDef`、`NgModule` 还是一个特殊的范围(例如 `'root'`)。如果值为 `null` 表示可注入对象不属于任何范围。 + * * @codeGenApi * @publicApi The ViewEngine compiler emits code with this type for injectables. This code is * deployed to npm, and should be treated as public api. @@ -30,28 +36,54 @@ import {ClassProvider, ConstructorProvider, ExistingProvider, FactoryProvider, S export interface ɵɵInjectableDef { /** * Specifies that the given type belongs to a particular injector: + * + * 指定给定类型属于特定的注入器: + * * - `InjectorType` such as `NgModule`, + * + * `InjectorType` 例如 `NgModule` , + * * - `'root'` the root injector + * + * `'root'` 根注入器 + * * - `'any'` all injectors. + * + * `'any'` 所有注入器。 + * * - `null`, does not belong to any injector. Must be explicitly listed in the injector * `providers`. + * + * `null` ,不属于任何注入器。必须在注入器的 `providers` 列表中显式列出。 + * */ providedIn: InjectorType|'root'|'platform'|'any'|null; /** * The token to which this definition belongs. * + * 此定义所属的令牌。 + * * Note that this may not be the same as the type that the `factory` will create. + * + * 请注意,这可能与 `factory` 将创建的类型不同。 + * */ token: unknown; /** * Factory method to execute to create an instance of the injectable. + * + * 本工厂方法用于创建可注入实例。 + * */ factory: (t?: Type) => T; /** * In a case of no explicit injector, a location where the instance of the injectable is stored. + * + * 在没有显式注入器的情况下,存储可注入实例的位置。 + * */ value: T|undefined; } @@ -82,14 +114,21 @@ export interface ɵɵInjectorDef { /** * A `Type` which has an `InjectableDef` static field. * + * 具有 `InjectableDef` 静态字段的 `Type` + * * `InjectableDefType`s contain their own Dependency Injection metadata and are usable in an * `InjectorDef`-based `StaticInjector. * + * `InjectableDefType` 包含其自己的依赖注入元数据,并且可在基于 `InjectorDef` 的 `StaticInjector` 中使用。 + * * @publicApi */ export interface InjectableType extends Type { /** * Opaque type whose structure is highly version dependent. Do not rely on any properties. + * + * 不透明类型,其结构高度依赖版本。不要依赖它的任何属性。 + * */ ɵprov: never; } @@ -97,13 +136,20 @@ export interface InjectableType extends Type { /** * A type which has an `InjectorDef` static field. * + * 具有 `InjectorDef` 静态字段的类型。 + * * `InjectorDefTypes` can be used to configure a `StaticInjector`. * + * 可用于配置 `StaticInjector` 的 `InjectorDefTypes`。 + * * @publicApi */ export interface InjectorType extends Type { /** * Opaque type whose structure is highly version dependent. Do not rely on any properties. + * + * 不透明类型,其结构高度依赖版本。不要依赖它的任何属性。 + * */ ɵinj: never; } @@ -127,16 +173,28 @@ export interface InjectorTypeWithProviders { * Construct an `InjectableDef` which defines how a token will be constructed by the DI system, and * in which injectors (if any) it will be available. * + * 构造一个 `InjectableDef` ,它定义 DI 体系将如何构造令牌以及在哪些注入器中可用(如果有的话)。 + * * This should be assigned to a static `ɵprov` field on a type, which will then be an * `InjectableType`. * + * 应该将其赋值给静态的 `ɵprov` 字段,然后将其作为 `InjectableType` 。 + * * Options: + * + * 选项: + * * * `providedIn` determines which injectors will include the injectable, by either associating it * with an `@NgModule` or other `InjectorType`, or by specifying that this injectable should be * provided in the `'root'` injector, which will be the application-level injector in most apps. + * + * `providedIn` 决定哪些注入器应该包含此可注入对象:或者将其与 `@NgModule` 关联,或者将其与其他 `InjectorType` 关联,或者指定应该在 `'root'` 注入器(对大多数应用来说这是全应用级注入器)中提供它。 + * * * `factory` gives the zero argument function which will create an instance of the injectable. * The factory can call `inject` to access the `Injector` and request injection of dependencies. * + * `factory` 是一个零参数函数,该函数将创建可注入的实例。工厂可以调用 `inject` 来访问 `Injector` 并请求注入依赖项。 + * * @codeGenApi * @publicApi This instruction has been emitted by ViewEngine for some time and is deployed to npm. */ @@ -155,6 +213,9 @@ export function ɵɵdefineInjectable(opts: { /** * @deprecated in v8, delete after v10. This API should be used only by generated code, and that * code should now use ɵɵdefineInjectable instead. + * + * 在 v8 中弃用,在 v10 之后删除。此 API 仅应由生成的代码使用,并且该代码现在应改用 ɵɵdefineInjectable。 + * * @publicApi */ export const defineInjectable = ɵɵdefineInjectable; diff --git a/packages/core/src/di/interface/injector.ts b/packages/core/src/di/interface/injector.ts index 9092ef5deb..72c78b2a27 100644 --- a/packages/core/src/di/interface/injector.ts +++ b/packages/core/src/di/interface/injector.ts @@ -10,22 +10,47 @@ /** * Injection flags for DI. * + * DI 的注入标志。 + * * @publicApi */ export enum InjectFlags { // TODO(alxhub): make this 'const' when ngc no longer writes exports of it into ngfactory files. - /** Check self and check parent injector if needed */ + /** + * Check self and check parent injector if needed + * + * 检查自身并检查父注入器(如果需要) + * + */ Default = 0b0000, /** * Specifies that an injector should retrieve a dependency from any injector until reaching the * host element of the current component. (Only used with Element Injector) + * + * 指定注入器应从任何注入器中检索依赖项,直到到达当前组件的宿主元素为止。(仅与元素注入器一起使用) + * */ Host = 0b0001, - /** Don't ascend to ancestors of the node requesting injection. */ + /** + * Don't ascend to ancestors of the node requesting injection. + * + * 不要上升到请求注入的节点的祖先去处理。 + * + */ Self = 0b0010, - /** Skip the node that is requesting injection. */ + /** + * Skip the node that is requesting injection. + * + * 跳过请求注入的节点。 + * + */ SkipSelf = 0b0100, - /** Inject `defaultValue` instead if token not found. */ + /** + * Inject `defaultValue` instead if token not found. + * + * 如果找不到令牌,则注入 `defaultValue` + * + */ Optional = 0b1000, } diff --git a/packages/core/src/di/interface/provider.ts b/packages/core/src/di/interface/provider.ts index 5504767610..104bebb118 100644 --- a/packages/core/src/di/interface/provider.ts +++ b/packages/core/src/di/interface/provider.ts @@ -12,23 +12,35 @@ import {Type} from '../../interface/type'; * Configures the `Injector` to return a value for a token. * Base for `ValueProvider` decorator. * + * 配置 `Injector` 以返回令牌的值。是 `ValueProvider` 装饰器的基接口。 + * * @publicApi */ export interface ValueSansProvider { /** * The value to inject. + * + * 要注入的值。 + * */ useValue: any; } /** * Configures the `Injector` to return a value for a token. + * + * 配置此 `Injector` 以返回令牌的值。 + * * @see ["Dependency Injection Guide"](guide/dependency-injection). * + * [“依赖注入指南”](guide/dependency-injection) 。 + * * @usageNotes * * ### Example * + * ### 例子 + * * {@example core/di/ts/provider_spec.ts region='ValueProvider'} * * ### Multi-value example @@ -40,12 +52,18 @@ export interface ValueSansProvider { export interface ValueProvider extends ValueSansProvider { /** * An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`. + * + * 注入令牌。通常是 `Type` 或 `InjectionToken` 的实例,但也可以是 `any` 实例。 + * */ provide: any; /** * When true, injector returns an array of instances. This is useful to allow multiple * providers spread across many files to provide configuration information to a common token. + * + * 如果为 true,则注入器返回实例数组。这对于允许多个提供者散布在多个文件中以向公共令牌提供配置信息很有用。 + * */ multi?: boolean; } @@ -54,26 +72,39 @@ export interface ValueProvider extends ValueSansProvider { * Configures the `Injector` to return an instance of `useClass` for a token. * Base for `StaticClassProvider` decorator. * + * 配置 `Injector` 以返回 `useClass` 的令牌实例。这是 `StaticClassProvider` 装饰器的基接口。 + * * @publicApi */ export interface StaticClassSansProvider { /** * An optional class to instantiate for the `token`. By default, the `provide` * class is instantiated. + * + * 供 `token` 实例化的可选类。默认情况下,会把 `provide` 类实例化。 + * */ useClass: Type; /** * A list of `token`s to be resolved by the injector. The list of values is then * used as arguments to the `useClass` constructor. + * + * 由注入器解析的 `token` 列表。将这个值列表用作 `useClass` 构造函数的参数。 + * */ deps: any[]; } /** * Configures the `Injector` to return an instance of `useClass` for a token. + * + * 配置 `Injector` 以返回 `useClass` 的令牌实例。 + * * @see ["Dependency Injection Guide"](guide/dependency-injection). * + * [“依赖注入指南”](guide/dependency-injection) 。 + * * @usageNotes * * {@example core/di/ts/provider_spec.ts region='StaticClassProvider'} @@ -91,12 +122,18 @@ export interface StaticClassSansProvider { export interface StaticClassProvider extends StaticClassSansProvider { /** * An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`. + * + * 注入令牌。通常是 `Type` 或 `InjectionToken` 的实例,但也可以是 `any` 实例。 + * */ provide: any; /** * When true, injector returns an array of instances. This is useful to allow multiple * providers spread across many files to provide configuration information to a common token. + * + * 如果为 true,则注入器返回实例数组。这在允许多个提供者散布在多个文件中,以向某个公共令牌提供配置信息时很有用。 + * */ multi?: boolean; } @@ -104,8 +141,11 @@ export interface StaticClassProvider extends StaticClassSansProvider { /** * Configures the `Injector` to return an instance of a token. * + * 配置此 `Injector` 以返回令牌的实例。 + * * @see ["Dependency Injection Guide"](guide/dependency-injection). * + * [“依赖注入指南”](guide/dependency-injection) 。 * @usageNotes * * ```ts @@ -118,6 +158,9 @@ export interface StaticClassProvider extends StaticClassSansProvider { export interface ConstructorSansProvider { /** * A list of `token`s to be resolved by the injector. + * + * 注入器要解析的 `token` 列表。 + * */ deps?: any[]; } @@ -125,8 +168,12 @@ export interface ConstructorSansProvider { /** * Configures the `Injector` to return an instance of a token. * + * 配置此 `Injector`,以返回令牌的实例。 + * * @see ["Dependency Injection Guide"](guide/dependency-injection). * + * [“依赖注入指南”](guide/dependency-injection) 。 + * * @usageNotes * * {@example core/di/ts/provider_spec.ts region='ConstructorProvider'} @@ -140,12 +187,18 @@ export interface ConstructorSansProvider { export interface ConstructorProvider extends ConstructorSansProvider { /** * An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`. + * + * 注入令牌。通常是 `Type` 或 `InjectionToken` 的实例,但也可以是 `any` 实例。 + * */ provide: Type; /** * When true, injector returns an array of instances. This is useful to allow multiple * providers spread across many files to provide configuration information to a common token. + * + * 如果为 true,则注入器返回实例数组。这对于允许多个提供者散布在多个文件中,以向某个公共令牌提供配置信息很有用。 + * */ multi?: boolean; } @@ -153,14 +206,21 @@ export interface ConstructorProvider extends ConstructorSansProvider { /** * Configures the `Injector` to return a value of another `useExisting` token. * + * 配置此 `Injector` 以返回另一个 `useExisting` 令牌的值。 + * * @see `ExistingProvider` * @see ["Dependency Injection Guide"](guide/dependency-injection). * + * [“依赖注入指南”](guide/dependency-injection) 。 + * * @publicApi */ export interface ExistingSansProvider { /** * Existing `token` to return. (Equivalent to `injector.get(useExisting)`) + * + * 返回现有的 `token`。 (等效于 `injector.get(useExisting)` ) + * */ useExisting: any; } @@ -168,8 +228,12 @@ export interface ExistingSansProvider { /** * Configures the `Injector` to return a value of another `useExisting` token. * + * 配置此 `Injector` 以返回另一个 `useExisting` 令牌的值。 + * * @see ["Dependency Injection Guide"](guide/dependency-injection). * + * [“依赖注入指南”](guide/dependency-injection) 。 + * * @usageNotes * * {@example core/di/ts/provider_spec.ts region='ExistingProvider'} @@ -183,12 +247,18 @@ export interface ExistingSansProvider { export interface ExistingProvider extends ExistingSansProvider { /** * An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`. + * + * 注入令牌。通常是 `Type` 或 `InjectionToken` 的实例,但也可以是 `any` 实例。 + * */ provide: any; /** * When true, injector returns an array of instances. This is useful to allow multiple * providers spread across many files to provide configuration information to a common token. + * + * 如果为 true,则注入器返回实例数组。这对于允许多个提供者散布在多个文件中,以向某个公共令牌提供配置信息很有用。 + * */ multi?: boolean; } @@ -196,29 +266,44 @@ export interface ExistingProvider extends ExistingSansProvider { /** * Configures the `Injector` to return a value by invoking a `useFactory` function. * + * 把此 `Injector` 配置为调用 `useFactory` 函数返回一个值。 + * * @see `FactoryProvider` * @see ["Dependency Injection Guide"](guide/dependency-injection). * + * [“依赖注入指南”](guide/dependency-injection) 。 + * * @publicApi */ export interface FactorySansProvider { /** * A function to invoke to create a value for this `token`. The function is invoked with * resolved values of `token`s in the `deps` field. + * + * 供调用,来为此 `token` 创建值的函数。调用该函数时,会在 `deps` 字段中的传入 `token` 的解析结果。。 + * */ useFactory: Function; /** * A list of `token`s to be resolved by the injector. The list of values is then * used as arguments to the `useFactory` function. + * + * 供注入器解析的 `token` 列表。然后,将值列表将用作 `useFactory` 函数的参数。 + * */ deps?: any[]; } /** * Configures the `Injector` to return a value by invoking a `useFactory` function. + * + * 配置此 `Injector` 以便调用 `useFactory` 函数返回一个值。 + * * @see ["Dependency Injection Guide"](guide/dependency-injection). * + * [“依赖注入指南”](guide/dependency-injection) 。 + * * @usageNotes * * {@example core/di/ts/provider_spec.ts region='FactoryProvider'} @@ -236,12 +321,18 @@ export interface FactorySansProvider { export interface FactoryProvider extends FactorySansProvider { /** * An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`). + * + * 注入令牌。(通常是 `Type` 或 `InjectionToken` 的实例,但也可以是 `any` 实例)。 + * */ provide: any; /** * When true, injector returns an array of instances. This is useful to allow multiple * providers spread across many files to provide configuration information to a common token. + * + * 如果为 true,则注入器返回实例数组。这对于允许多个提供者散布在多个文件中,以向某个公共令牌提供配置信息很有用。 + * */ multi?: boolean; } @@ -250,9 +341,13 @@ export interface FactoryProvider extends FactorySansProvider { * Describes how an `Injector` should be configured as static (that is, without reflection). * A static provider provides tokens to an injector for various types of dependencies. * + * 描述如何将 `Injector` 配置为静态的(即不需要反射)。静态提供者为各种类型的依赖项提供令牌给注入器。 + * * @see [Injector.create()](/api/core/Injector#create). * @see ["Dependency Injection Guide"](guide/dependency-injection-providers). * + * [“依赖注入指南”](guide/dependency-injection-providers) 。 + * * @publicApi */ export type StaticProvider = @@ -262,11 +357,17 @@ export type StaticProvider = /** * Configures the `Injector` to return an instance of `Type` when `Type' is used as the token. * + * 配置此 `Injector`,以将“类型”用作令牌时返回 `Type` 的实例。 + * * Create an instance by invoking the `new` operator and supplying additional arguments. * This form is a short form of `TypeProvider`; * + * 通过调用 `new` 运算符并提供其他参数来创建实例。这种形式是 `TypeProvider` 的缩写形式; + * * For more details, see the ["Dependency Injection Guide"](guide/dependency-injection). * + * 欲知详情,请参见[“依赖项注入指南”](guide/dependency-injection) 。 + * * @usageNotes * * {@example core/di/ts/provider_spec.ts region='TypeProvider'} @@ -279,21 +380,33 @@ export interface TypeProvider extends Type {} * Configures the `Injector` to return a value by invoking a `useClass` function. * Base for `ClassProvider` decorator. * + * 配置 `Injector` 以通过调用 `useClass` 函数返回某个值。是 `ClassProvider` 装饰器的基接口。 + * * @see ["Dependency Injection Guide"](guide/dependency-injection). * + * [“依赖注入指南”](guide/dependency-injection) 。 + * * @publicApi */ export interface ClassSansProvider { /** * Class to instantiate for the `token`. + * + * 用于将此 `token` 实例化的类。 + * */ useClass: Type; } /** * Configures the `Injector` to return an instance of `useClass` for a token. + * + * 配置此 `Injector` 以便为令牌返回 `useClass` 的实例。 + * * @see ["Dependency Injection Guide"](guide/dependency-injection). * + * [“依赖注入指南”](guide/dependency-injection) 。 + * * @usageNotes * * {@example core/di/ts/provider_spec.ts region='ClassProvider'} @@ -311,20 +424,31 @@ export interface ClassSansProvider { export interface ClassProvider extends ClassSansProvider { /** * An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`). + * + * 注入令牌。(通常是 `Type` 或 `InjectionToken` 的实例,但也可以是 `any` 实例)。 + * */ provide: any; /** * When true, injector returns an array of instances. This is useful to allow multiple * providers spread across many files to provide configuration information to a common token. + * + * 如果为 true,则注入器返回实例数组。这对于允许多个提供者散布在多个文件中,以向某个公共令牌提供配置信息时很有用。 + * */ multi?: boolean; } /** * Describes how the `Injector` should be configured. + * + * 描述应该如何配置 `Injector`。 + * * @see ["Dependency Injection Guide"](guide/dependency-injection). * + * [“依赖注入指南”](guide/dependency-injection) 。 + * * @see `StaticProvider` * * @publicApi diff --git a/packages/core/src/di/metadata.ts b/packages/core/src/di/metadata.ts index d3e9275f03..9a3725af97 100644 --- a/packages/core/src/di/metadata.ts +++ b/packages/core/src/di/metadata.ts @@ -12,6 +12,8 @@ import {makeParamDecorator} from '../util/decorators'; /** * Type of the Inject decorator / constructor function. * + * 注入装饰器/构造函数的类型。 + * * @publicApi */ export interface InjectDecorator { @@ -19,18 +21,27 @@ export interface InjectDecorator { * Parameter decorator on a dependency parameter of a class constructor * that specifies a custom provider of the dependency. * + * 类构造函数中依赖项参数上的参数装饰器,用于指定依赖项的自定义提供者。 + * * @usageNotes + * * The following example shows a class constructor that specifies a * custom provider of a dependency using the parameter decorator. * + * 下面的示例显示了一个类构造函数,该构造函数使用参数装饰器指定了依赖项的自定义提供者。 + * * When `@Inject()` is not present, the injector uses the type annotation of the * parameter as the provider. * + * 如果有 `@Inject()`,则注入器将参数的类型注解用作提供者。 + * * * * * @see ["Dependency Injection Guide"](guide/dependency-injection) * + * [“依赖注入指南”](guide/dependency-injection) + * */ (token: any): any; new(token: any): Inject; @@ -39,11 +50,16 @@ export interface InjectDecorator { /** * Type of the Inject metadata. * + * 注入元数据的类型。 + * * @publicApi */ export interface Inject { /** * A [DI token](guide/glossary#di-token) that maps to the dependency to be injected. + * + * 一个 [DI 令牌](guide/glossary#di-token),映射到要注入的依赖项。 + * */ token: any; } @@ -51,6 +67,8 @@ export interface Inject { /** * Inject decorator and metadata. * + * 注入装饰器和元数据。 + * * @Annotation * @publicApi */ @@ -60,6 +78,8 @@ export const Inject: InjectDecorator = makeParamDecorator('Inject', (token: any) /** * Type of the Optional decorator / constructor function. * + * 可选装饰器/构造函数的类型。 + * * @publicApi */ export interface OptionalDecorator { @@ -68,17 +88,26 @@ export interface OptionalDecorator { * which marks the parameter as being an optional dependency. * The DI framework provides null if the dependency is not found. * + * 用于构造函数参数的参数装饰器,将参数标记为可选依赖项。如果找不到依赖项,则 DI 框架提供 null。 + * * Can be used together with other parameter decorators * that modify how dependency injection operates. * + * 可以与其他修改依赖注入方式的参数装饰器一起使用。 + * * @usageNotes * * The following code allows the possibility of a null result: * + * 以下代码允许结果为空的可能性: + * * * * * @see ["Dependency Injection Guide"](guide/dependency-injection). + * + * [“依赖注入指南”](guide/dependency-injection) 。 + * */ (): any; new(): Optional; @@ -87,6 +116,8 @@ export interface OptionalDecorator { /** * Type of the Optional metadata. * + * 可选元数据的类型。 + * * @publicApi */ export interface Optional {} @@ -94,6 +125,8 @@ export interface Optional {} /** * Optional decorator and metadata. * + * 可选的装饰器和元数据。 + * * @Annotation * @publicApi */ @@ -102,6 +135,8 @@ export const Optional: OptionalDecorator = makeParamDecorator('Optional'); /** * Type of the Self decorator / constructor function. * + * Self 装饰器/构造函数的类型。 + * * @publicApi */ export interface SelfDecorator { @@ -109,15 +144,21 @@ export interface SelfDecorator { * Parameter decorator to be used on constructor parameters, * which tells the DI framework to start dependency resolution from the local injector. * + * 将在构造函数参数上使用参数装饰器,该装饰器告诉 DI 框架从本地注入器开始解析依赖项。 + * * Resolution works upward through the injector hierarchy, so the children * of this class must configure their own providers or be prepared for a null result. * + * 解析器在注入器层次结构中向上查找,因此此类的子级必须配置其自己的提供者或为空结果做好准备。 + * * @usageNotes * * In the following example, the dependency can be resolved * by the local injector when instantiating the class itself, but not * when instantiating a child. * + * 在以下示例中,依赖关系可以在实例化类本身时由本地注入器解析,而在实例化子代时不能解析。 + * * * * @@ -132,6 +173,8 @@ export interface SelfDecorator { /** * Type of the Self metadata. * + * Self 元数据的类型。 + * * @publicApi */ export interface Self {} @@ -139,6 +182,8 @@ export interface Self {} /** * Self decorator and metadata. * + * Self 装饰器和元数据。 + * * @Annotation * @publicApi */ @@ -148,6 +193,8 @@ export const Self: SelfDecorator = makeParamDecorator('Self'); /** * Type of the `SkipSelf` decorator / constructor function. * + * `SkipSelf` 装饰器/构造函数的类型。 + * * @publicApi */ export interface SkipSelfDecorator { @@ -157,15 +204,22 @@ export interface SkipSelfDecorator { * Resolution works upward through the injector hierarchy, so the local injector * is not checked for a provider. * + * 将在构造函数参数上使用的参数装饰器,该参数指示 DI 框架从父注入器启动依赖项解析。解析器在注入器层次结构中向上查找,因此不会检查本地注入器的提供者。 + * * @usageNotes * * In the following example, the dependency can be resolved when * instantiating a child, but not when instantiating the class itself. * + * 在以下示例中,可以在实例化子级时解析依赖项,但在实例化类本身时不解析。 + * * * * * @see [Dependency Injection guide](guide/dependency-injection-in-action#skip). + * + * [依赖注入指南](guide/dependency-injection-in-action#skip)。 + * * @see `Self` * @see `Optional` * @@ -177,6 +231,8 @@ export interface SkipSelfDecorator { /** * Type of the `SkipSelf` metadata. * + * `SkipSelf` 元数据的类型。 + * * @publicApi */ export interface SkipSelf {} @@ -184,6 +240,8 @@ export interface SkipSelf {} /** * `SkipSelf` decorator and metadata. * + * `SkipSelf` 装饰器和元数据。 + * * @Annotation * @publicApi */ @@ -192,6 +250,8 @@ export const SkipSelf: SkipSelfDecorator = makeParamDecorator('SkipSelf'); /** * Type of the `Host` decorator / constructor function. * + * `Host` 装饰器/构造函数的类型。 + * * @publicApi */ export interface HostDecorator { @@ -200,15 +260,22 @@ export interface HostDecorator { * that tells the DI framework to resolve the view by checking injectors of child * elements, and stop when reaching the host element of the current component. * + * 类构造函数的视图提供者参数上的参数修饰器,用于指示 DI 框架通过检查子元素的注入器来解析视图,并在到达当前组件的宿主元素时停止。 + * * @usageNotes * * The following shows use with the `@Optional` decorator, and allows for a null result. * + * 以下显示了与 `@Optional` 装饰器一起使用的情况,并允许空结果。 + * * * * * For an extended example, see ["Dependency Injection * Guide"](guide/dependency-injection-in-action#optional). + * + * 有关扩展的示例,请参见[“依赖项注入指南”](guide/dependency-injection-in-action#optional) 。 + * */ (): any; new(): Host; @@ -217,6 +284,8 @@ export interface HostDecorator { /** * Type of the Host metadata. * + * 宿主元数据的类型。 + * * @publicApi */ export interface Host {} @@ -224,6 +293,8 @@ export interface Host {} /** * Host decorator and metadata. * + * 宿主装饰器和元数据。 + * * @Annotation * @publicApi */ diff --git a/packages/core/src/di/metadata_attr.ts b/packages/core/src/di/metadata_attr.ts index bee9d66c42..7d564a4e65 100644 --- a/packages/core/src/di/metadata_attr.ts +++ b/packages/core/src/di/metadata_attr.ts @@ -13,6 +13,8 @@ import {makeParamDecorator} from '../util/decorators'; /** * Type of the Attribute decorator / constructor function. * + * 属性装饰器/构造函数的类型。 + * * @publicApi */ export interface AttributeDecorator { @@ -20,16 +22,22 @@ export interface AttributeDecorator { * Parameter decorator for a directive constructor that designates * a host-element attribute whose value is injected as a constant string literal. * + * 指令构造函数的参数修饰器,用于指定宿主元素属性,其值作为常量字符串文字注入。 + * * @usageNotes * * Suppose we have an `` element and want to know its `type`. * + * 假设我们有一个 `` 元素,并且想知道它的 `type` 。 + * * ```html * * ``` * * The following example uses the decorator to inject the string literal `text` in a directive. * + * 以下示例使用装饰器将字符串文字 `text` 注入指令中。 + * * {@example core/ts/metadata/metadata.ts region='attributeMetadata'} * * The following example uses the decorator in a component constructor. @@ -44,11 +52,16 @@ export interface AttributeDecorator { /** * Type of the Attribute metadata. * + * 属性元数据的类型。 + * * @publicApi */ export interface Attribute { /** * The name of the attribute whose value can be injected. + * + * 可以注入其值的属性的名称。 + * */ attributeName: string; } @@ -69,6 +82,8 @@ const CREATE_ATTRIBUTE_DECORATOR_IMPL = CREATE_ATTRIBUTE_DECORATOR__PRE_R3__; /** * Attribute decorator and metadata. * + * 属性装饰器和元数据。 + * * @Annotation * @publicApi */ diff --git a/packages/core/src/di/r3_injector.ts b/packages/core/src/di/r3_injector.ts index c993e6a738..57e1d6187f 100644 --- a/packages/core/src/di/r3_injector.ts +++ b/packages/core/src/di/r3_injector.ts @@ -75,6 +75,8 @@ interface Record { /** * Create a new `Injector` which is configured using a `defType` of `InjectorType`s. * + * 创建一个新的 `Injector`, 它是使用 `InjectorType` 的 `defType` 配置的。 + * * @publicApi */ export function createInjector( diff --git a/packages/core/src/di/reflective_errors.ts b/packages/core/src/di/reflective_errors.ts index af4e04b2fb..42a1416503 100644 --- a/packages/core/src/di/reflective_errors.ts +++ b/packages/core/src/di/reflective_errors.ts @@ -70,6 +70,7 @@ function addKey(this: InjectionError, injector: ReflectiveInjector, key: Reflect * {@link Injector} does not have a {@link Provider} for the given key. * * @usageNotes + * * ### Example * * ```typescript @@ -91,6 +92,7 @@ export function noProviderError(injector: ReflectiveInjector, key: ReflectiveKey * Thrown when dependencies form a cycle. * * @usageNotes + * * ### Example * * ```typescript @@ -118,6 +120,7 @@ export function cyclicDependencyError( * this object to be instantiated. * * @usageNotes + * * ### Example * * ```typescript @@ -153,6 +156,7 @@ export function instantiationError( * creation. * * @usageNotes + * * ### Example * * ```typescript @@ -171,6 +175,7 @@ export function invalidProviderError(provider: any) { * need to be injected into the constructor. * * @usageNotes + * * ### Example * * ```typescript @@ -215,6 +220,7 @@ export function noAnnotationError(typeOrFunc: Type|Function, params: any[][ * Thrown when getting an object by index. * * @usageNotes + * * ### Example * * ```typescript @@ -235,6 +241,7 @@ export function outOfBoundsError(index: number) { * Thrown when a multi provider and a regular provider are bound to the same token. * * @usageNotes + * * ### Example * * ```typescript diff --git a/packages/core/src/di/reflective_injector.ts b/packages/core/src/di/reflective_injector.ts index 43192d1e16..c77259ea4c 100644 --- a/packages/core/src/di/reflective_injector.ts +++ b/packages/core/src/di/reflective_injector.ts @@ -22,17 +22,28 @@ const UNDEFINED = {}; * A ReflectiveDependency injection container used for instantiating objects and resolving * dependencies. * + * 一个 ReflectiveDependency 注入容器,用于实例化对象和解析依赖关系。 + * * An `Injector` is a replacement for a `new` operator, which can automatically resolve the * constructor dependencies. * + * `Injector` 替代了 `new` 操作符,该操作符可以自动解析构造函数的依赖关系。 + * * In typical use, application code asks for the dependencies in the constructor and they are * resolved by the `Injector`. * + * 在典型的用法中,应用程序代码会在构造函数中要求依赖项,并由 `Injector` 进行解析。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * The following example creates an `Injector` configured to create `Engine` and `Car`. * + * 以下示例创建一个配置为创建 `Engine` 和 `Car` 的 `Injector`。 + * * ```typescript * @Injectable() * class Engine { @@ -53,18 +64,28 @@ const UNDEFINED = {}; * resolve all of the object's dependencies automatically. * * @deprecated from v5 - slow and brings in a lot of code, Use `Injector.create` instead. + * + * 从 v5 开始 - 速度慢,并且引入了大量代码,请改用 `Injector.create` 。 + * * @publicApi */ export abstract class ReflectiveInjector implements Injector { /** * Turns an array of provider definitions into an array of resolved providers. * + * 将一组提供者定义转换为一组已解析的提供者。 + * * A resolution is a process of flattening multiple nested arrays and converting individual * providers into an array of `ResolvedReflectiveProvider`s. * + * 解析是展平多个嵌套数组并将其各个提供者转换为 `ResolvedReflectiveProvider` 数组的过程。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * ```typescript * @Injectable() * class Engine { @@ -96,12 +117,19 @@ export abstract class ReflectiveInjector implements Injector { /** * Resolves an array of providers and creates an injector from those providers. * + * 解析供应商数组,并从这些供应商创建注入器。 + * * The passed-in providers can be an array of `Type`, `Provider`, * or a recursive array of more providers. * + * 传入的提供者可以是 `Type`、`Provider` 或更多提供者的递归数组。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * ```typescript * @Injectable() * class Engine { @@ -124,11 +152,18 @@ export abstract class ReflectiveInjector implements Injector { /** * Creates an injector from previously resolved providers. * + * 从先前解析的提供者创建注入器。 + * * This API is the recommended way to construct injectors in performance-sensitive parts. * + * 建议使用此 API 在对性能敏感的部分构建注入器。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * ```typescript * @Injectable() * class Engine { @@ -153,6 +188,8 @@ export abstract class ReflectiveInjector implements Injector { /** * Parent of this injector. * + * 此注入器的父代。 + * * */ @@ -161,15 +198,22 @@ export abstract class ReflectiveInjector implements Injector { /** * Resolves an array of providers and creates a child injector from those providers. * + * 解析一组提供者,并从这些提供者创建子注入器。 + * * * * The passed-in providers can be an array of `Type`, `Provider`, * or a recursive array of more providers. * + * 传入的提供者可以是 `Type`、`Provider` 或更多提供者的递归数组。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * ```typescript * class ParentProvider {} * class ChildProvider {} @@ -187,14 +231,21 @@ export abstract class ReflectiveInjector implements Injector { /** * Creates a child injector from previously resolved providers. * + * 从先前解析的提供者中创建子注入器。 + * * * * This API is the recommended way to construct injectors in performance-sensitive parts. * + * 建议使用此 API 在对性能敏感的部分构造注入器。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * ```typescript * class ParentProvider {} * class ChildProvider {} @@ -215,11 +266,18 @@ export abstract class ReflectiveInjector implements Injector { /** * Resolves a provider and instantiates an object in the context of the injector. * + * 解析提供者并在注入器的上下文中实例化对象。 + * * The created object does not get cached by the injector. * + * 注入器不会缓存创建的对象。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * ```typescript * @Injectable() * class Engine { @@ -242,11 +300,18 @@ export abstract class ReflectiveInjector implements Injector { /** * Instantiates an object using a resolved provider in the context of the injector. * + * 在注入器的上下文中使用解析的提供者实例化对象。 + * * The created object does not get cached by the injector. * + * 注入器不会缓存创建的对象。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * ```typescript * @Injectable() * class Engine { diff --git a/packages/core/src/di/reflective_key.ts b/packages/core/src/di/reflective_key.ts index a3323a8cfb..865d0aad01 100644 --- a/packages/core/src/di/reflective_key.ts +++ b/packages/core/src/di/reflective_key.ts @@ -13,25 +13,45 @@ import {resolveForwardRef} from './forward_ref'; /** * A unique object used for retrieving items from the {@link ReflectiveInjector}. * + * 用于从 {@link ReflectiveInjector} 中检索项目的唯一对象。 + * * Keys have: + * + * 其键名有: + * * - a system-wide unique `id`. + * + * 系统范围内的唯一 `id` 。 + * * - a `token`. * + * `token`。 + * * `Key` is used internally by {@link ReflectiveInjector} because its system-wide unique `id` allows * the * injector to store created objects in a more efficient way. * + * `Key` 由 {@link ReflectiveInjector} 内部使用,因为它在系统范围内的唯一 `id` 允许注入器以更有效的方式存储所创建的对象。 + * * `Key` should not be created directly. {@link ReflectiveInjector} creates keys automatically when * resolving * providers. * + * `Key` 不应直接创建。{@link ReflectiveInjector} 在解析提供者时会自动创建键名。 + * * @deprecated No replacement + * + * 无替代品 + * * @publicApi */ export class ReflectiveKey { public readonly displayName: string; /** * Private + * + * 私人的 + * */ constructor(public token: Object, public id: number) { if (!token) { @@ -42,6 +62,9 @@ export class ReflectiveKey { /** * Retrieves a `Key` for a token. + * + * 根据令牌检索出一个 `Key`。 + * */ static get(token: Object): ReflectiveKey { return _globalKeyRegistry.get(resolveForwardRef(token)); @@ -49,6 +72,9 @@ export class ReflectiveKey { /** * @returns the number of keys registered in the system. + * + * 在系统中注册的 `Key` 数。 + * */ static get numberOfKeys(): number { return _globalKeyRegistry.numberOfKeys; diff --git a/packages/core/src/di/reflective_provider.ts b/packages/core/src/di/reflective_provider.ts index 77e5cee81b..7cda008a80 100644 --- a/packages/core/src/di/reflective_provider.ts +++ b/packages/core/src/di/reflective_provider.ts @@ -38,13 +38,22 @@ const _EMPTY_LIST: any[] = []; /** * An internal resolved representation of a `Provider` used by the `Injector`. * + * 供 `Injector` 使用的 `Provider` 的内部解析表示形式。 + * * @usageNotes + * * This is usually created automatically by `Injector.resolveAndCreate`. * + * 这通常是由 `Injector.resolveAndCreate` 自动创建的。 + * * It can be created manually, as follows: * + * 也可以手动创建,如下所示: + * * ### Example * + * ### 例子 + * * ```typescript * var resolvedProviders = Injector.resolve([{ provide: 'message', useValue: 'Hello' }]); * var injector = Injector.fromResolvedProviders(resolvedProviders); @@ -57,16 +66,25 @@ const _EMPTY_LIST: any[] = []; export interface ResolvedReflectiveProvider { /** * A key, usually a `Type`. + * + * 一个 Key,通常是 `Type` 。 + * */ key: ReflectiveKey; /** * Factory function which can return an instance of an object represented by a key. + * + * 可以返回 Key 表示的对象实例的工厂函数。 + * */ resolvedFactories: ResolvedReflectiveFactory[]; /** * Indicates if the provider is a multi-provider or a regular provider. + * + * 指示提供者是多重提供者还是常规提供者。 + * */ multiProvider: boolean; } @@ -83,6 +101,9 @@ export class ResolvedReflectiveProvider_ implements ResolvedReflectiveProvider { /** * An internal resolved representation of a factory function created by resolving `Provider`. + * + * `Provider` 创建的工厂函数的内部解析表示形式。 + * * @publicApi */ export class ResolvedReflectiveFactory { diff --git a/packages/core/src/error_handler.ts b/packages/core/src/error_handler.ts index 7f5ec2748e..41e4596786 100644 --- a/packages/core/src/error_handler.ts +++ b/packages/core/src/error_handler.ts @@ -13,13 +13,20 @@ import {getDebugContext, getErrorLogger, getOriginalError} from './errors'; /** * Provides a hook for centralized exception handling. * + * 提供用于集中式异常处理的挂钩。 + * * The default implementation of `ErrorHandler` prints error messages to the `console`. To * intercept error handling, write a custom exception handler that replaces this default as * appropriate for your app. * + * `ErrorHandler` 的默认实现将错误消息打印到 `console`。要拦截错误处理,请编写一个自定义的异常处理器,该异常处理器将把此默认行为改成你应用所需的。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * ``` * class MyErrorHandler implements ErrorHandler { * handleError(error) { diff --git a/packages/core/src/event_emitter.ts b/packages/core/src/event_emitter.ts index bae23359d4..ea66c1b33e 100644 --- a/packages/core/src/event_emitter.ts +++ b/packages/core/src/event_emitter.ts @@ -15,16 +15,22 @@ import {Subject, Subscription} from 'rxjs'; * synchronously or asynchronously, and register handlers for those events * by subscribing to an instance. * + * 用在带有 `@Output` 指令的组件中,以同步或异步方式发出自定义事件,并通过订阅实例来为这些事件注册处理器。 + * * @usageNotes * * Extends * [RxJS `Subject`](https://rxjs.dev/api/index/class/Subject) * for Angular by adding the `emit()` method. * + * 通过添加 `emit()` 方法来扩展 [Angular 的 RxJS `Subject`](https://rxjs.dev/api/index/class/Subject)。 + * * In the following example, a component defines two output properties * that create event emitters. When the title is clicked, the emitter * emits an open or close event to toggle the current visibility state. * + * 在以下示例中,组件定义了两个创建事件发射器的输出属性。单击标题后,发射器将发出打开或关闭事件以切换当前可见性状态。 + * * ```html * @Component({ * selector: 'zippy', @@ -59,6 +65,9 @@ import {Subject, Subscription} from 'rxjs'; * ``` * * @see [Observables in Angular](guide/observables-in-angular) + * + * [Angular 中的可观察对象](guide/observables-in-angular) + * * @publicApi */ export interface EventEmitter extends Subject { @@ -71,6 +80,8 @@ export interface EventEmitter extends Subject { * Creates an instance of this class that can * deliver events synchronously or asynchronously. * + * 创建此类的实例,该实例可以同步或异步发送事件。 + * * @param [isAsync=false] When true, deliver events asynchronously. * */ @@ -78,16 +89,34 @@ export interface EventEmitter extends Subject { /** * Emits an event containing a given value. + * + * 发出包含给定值的事件。 + * * @param value The value to emit. + * + * 要发出的值。 + * */ emit(value?: T): void; /** * Registers handlers for events emitted by this instance. + * + * 注册此实例发出的事件的处理器。 + * * @param generatorOrNext When supplied, a custom handler for emitted events. + * + * 如果提供,则为所发出事件的自定义处理器。 + * * @param error When supplied, a custom handler for an error notification * from this emitter. + * + * 如果提供,则为这里发出的错误通知的自定义处理器。 + * * @param complete When supplied, a custom handler for a completion * notification from this emitter. + * + * 如果提供,则为这里发出的完成通知的自定义处理器。 + * */ subscribe(generatorOrNext?: any, error?: any, complete?: any): Subscription; } diff --git a/packages/core/src/i18n/tokens.ts b/packages/core/src/i18n/tokens.ts index 91a57caa94..46867fa81f 100644 --- a/packages/core/src/i18n/tokens.ts +++ b/packages/core/src/i18n/tokens.ts @@ -13,11 +13,18 @@ import {InjectionToken} from '../di/injection_token'; * It is used for i18n extraction, by i18n pipes (DatePipe, I18nPluralPipe, CurrencyPipe, * DecimalPipe and PercentPipe) and by ICU expressions. * + * 提供此令牌以设置应用程序的语言环境。它通过 i18n 管道(DatePipe、I18nPluralPipe、CurrencyPipe、DecimalPipe 和 PercentPipe)和 ICU 表达式用于 i18n 提取。 + * * See the [i18n guide](guide/i18n#setting-up-locale) for more information. * + * 有关更多信息,请参见《 [i18n 指南》。](guide/i18n#setting-up-locale) + * * @usageNotes + * * ### Example * + * ### 例子 + * * ```typescript * import { LOCALE_ID } from '@angular/core'; * import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; @@ -37,19 +44,31 @@ export const LOCALE_ID = new InjectionToken('LocaleId'); * CurrencyPipe when there is no currency code passed into it. This is only used by * CurrencyPipe and has no relation to locale currency. Defaults to USD if not configured. * + * 如果没有传递任何货币代码,请提供此令牌来设置你的应用程序用于 CurrencyPipe 的默认货币代码。仅由 CurrencyPipe 使用,与语言环境的货币无关。如果未配置,则默认为 USD。 + * * See the [i18n guide](guide/i18n#setting-up-locale) for more information. * + * 有关更多信息,请参见[《i18n 指南》](guide/i18n#setting-up-locale)。 + * *
    * * **Deprecation notice:** * + * **弃用通知:** + * * The default currency code is currently always `USD` but this is deprecated from v9. * + * 默认货币代码当前始终为 `USD` 但自 v9 起已弃用。 + * * **In v10 the default currency code will be taken from the current locale.** * + * **在 v10 中,默认货币代码将从当前语言环境中获取。** + * * If you need the previous behavior then set it by creating a `DEFAULT_CURRENCY_CODE` provider in * your application `NgModule`: * + * 如果你需要以前的行为,请通过应用 `NgModule` 中的 `DEFAULT_CURRENCY_CODE` 提供者来进行设置: + * * ```ts * {provide: DEFAULT_CURRENCY_CODE, useValue: 'USD'} * ``` @@ -57,8 +76,11 @@ export const LOCALE_ID = new InjectionToken('LocaleId'); *
    * * @usageNotes + * * ### Example * + * ### 例子 + * * ```typescript * import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; * import { AppModule } from './app/app.module'; @@ -76,11 +98,18 @@ export const DEFAULT_CURRENCY_CODE = new InjectionToken('DefaultCurrency * Use this token at bootstrap to provide the content of your translation file (`xtb`, * `xlf` or `xlf2`) when you want to translate your application in another language. * + * 当你想用另一种语言翻译应用程序时,可以在引导程序中使用此令牌来提供翻译文件的内容( `xtb`、`xlf` 或 `xlf2`) + * * See the [i18n guide](guide/i18n#merge) for more information. * + * 有关更多信息,请参见[《i18n 指南》](guide/i18n#setting-up-locale)。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * ```typescript * import { TRANSLATIONS } from '@angular/core'; * import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; @@ -102,11 +131,18 @@ export const TRANSLATIONS = new InjectionToken('Translations'); * Provide this token at bootstrap to set the format of your {@link TRANSLATIONS}: `xtb`, * `xlf` or `xlf2`. * + * 在引导程序中提供此令牌以设置 {@link TRANSLATIONS} 的格式: `xtb`、`xlf` 或 `xlf2`。 + * * See the [i18n guide](guide/i18n#merge) for more information. * + * 有关更多信息,请参见[《i18n 指南》](guide/i18n#setting-up-locale)。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * ```typescript * import { TRANSLATIONS_FORMAT } from '@angular/core'; * import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; @@ -124,14 +160,31 @@ export const TRANSLATIONS_FORMAT = new InjectionToken('TranslationsForma /** * Use this enum at bootstrap as an option of `bootstrapModule` to define the strategy * that the compiler should use in case of missing translations: + * + * 在系统启动时使用此枚举作为 `bootstrapModule` 的一个选项来定义策略,编译器应该在缺少翻译的情况下使用: + * * - Error: throw if you have missing translations. + * + * Error:如果缺少翻译,则抛出该错误。 + * * - Warning (default): show a warning in the console and/or shell. + * + * Warning(默认):在控制台和/或应用外壳中显示警告。 + * * - Ignore: do nothing. * + * Ignore:什么都不做。 + * * See the [i18n guide](guide/i18n#missing-translation) for more information. * + * 有关更多信息,请参见[《i18n 指南》](guide/i18n#setting-up-locale)。 + * * @usageNotes + * * ### Example + * + * ### 例子 + * * ```typescript * import { MissingTranslationStrategy } from '@angular/core'; * import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; diff --git a/packages/core/src/interface/lifecycle_hooks.ts b/packages/core/src/interface/lifecycle_hooks.ts index f133c1aad9..fce7f09aee 100644 --- a/packages/core/src/interface/lifecycle_hooks.ts +++ b/packages/core/src/interface/lifecycle_hooks.ts @@ -23,6 +23,7 @@ import {SimpleChanges} from './simple_change'; * [生命周期钩子](guide/lifecycle-hooks#onchanges) * * @usageNotes + * * The following snippet shows how a component can implement this interface to * define an on-changes handler for an input property. * @@ -63,6 +64,7 @@ export interface OnChanges { * [生命周期钩子](guide/lifecycle-hooks#onchanges) * * @usageNotes + * * The following snippet shows how a component can implement this interface to * define its own initialization method. * @@ -113,6 +115,7 @@ export interface OnInit { * [生命周期钩子](guide/lifecycle-hooks#onchanges) * * @usageNotes + * * The following snippet shows how a component can implement this interface * to invoke it own change-detection cycle. * @@ -151,6 +154,7 @@ export interface DoCheck { * [生命周期钩子](guide/lifecycle-hooks#onchanges) * * @usageNotes + * * The following snippet shows how a component can implement this interface * to define its own custom clean-up method. * @@ -186,6 +190,7 @@ export interface OnDestroy { * [生命周期钩子](guide/lifecycle-hooks#onchanges) * * @usageNotes + * * The following snippet shows how a component can implement this interface to * define its own content initialization method. * @@ -222,6 +227,7 @@ export interface AfterContentInit { * [生命周期钩子](guide/lifecycle-hooks#onchanges) * * @usageNotes + * * The following snippet shows how a component can implement this interface to * define its own after-check functionality. * @@ -258,6 +264,7 @@ export interface AfterContentChecked { * [生命周期钩子](guide/lifecycle-hooks#onchanges) * * @usageNotes + * * The following snippet shows how a component can implement this interface to * define its own view initialization method. * @@ -292,6 +299,7 @@ export interface AfterViewInit { * [生命周期钩子](guide/lifecycle-hooks#onchanges) * * @usageNotes + * * The following snippet shows how a component can implement this interface to * define its own after-check functionality. * diff --git a/packages/core/src/interface/simple_change.ts b/packages/core/src/interface/simple_change.ts index eb34f63233..21bc5b35b1 100644 --- a/packages/core/src/interface/simple_change.ts +++ b/packages/core/src/interface/simple_change.ts @@ -11,6 +11,8 @@ * property on a directive instance. Passed as a value in a * {@link SimpleChanges} object to the `ngOnChanges` hook. * + * 表示指令实例上单个属性从先前值到新值的基本变更对象。在 {@link SimpleChanges} 对象中作为值传递给 `ngOnChanges` 挂钩。 + * * @see `OnChanges` * * @publicApi @@ -19,6 +21,9 @@ export class SimpleChange { constructor(public previousValue: any, public currentValue: any, public firstChange: boolean) {} /** * Check whether the new value is the first value assigned. + * + * 检查新值是否是首次赋值的。 + * */ isFirstChange(): boolean { return this.firstChange; @@ -30,6 +35,8 @@ export class SimpleChange { * at the declared property name they belong to on a Directive or Component. This is * the type passed to the `ngOnChanges` hook. * + * 用 {@link SimpleChange} 对象表示的变更的哈希表,这些对象以声明的属性名称存储在指令或组件上,这些属性属于它们。这是传递给 `ngOnChanges` 钩子的类型。 + * * @see `OnChanges` * * @publicApi diff --git a/packages/core/src/interface/type.ts b/packages/core/src/interface/type.ts index cbacc039ed..a02ee1d353 100644 --- a/packages/core/src/interface/type.ts +++ b/packages/core/src/interface/type.ts @@ -11,9 +11,13 @@ * * Represents a type that a Component or other object is instances of. * + * 表示 Component 或其他对象的类型。 + * * An example of a `Type` is `MyCustomComponent` class, which in JavaScript is represented by * the `MyCustomComponent` constructor function. * + * `Type` 的例子之一是 `MyCustomComponent` 类,该类在 JavaScript 中由 `MyCustomComponent` 构造函数表示。 + * * @publicApi */ export const Type = Function; @@ -28,6 +32,8 @@ export function isType(v: any): v is Type { * Represents an abstract class `T`, if applied to a concrete class it would stop being * instantiable. * + * 表示抽象类 `T`,如果将其应用于具体类,它将无法被实例化。 + * * @publicApi */ export interface AbstractType extends Function { diff --git a/packages/core/src/linker/compiler.ts b/packages/core/src/linker/compiler.ts index 74d46eee1a..d76138f106 100644 --- a/packages/core/src/linker/compiler.ts +++ b/packages/core/src/linker/compiler.ts @@ -25,6 +25,8 @@ import {NgModuleFactory} from './ng_module_factory'; /** * Combination of NgModuleFactory and ComponentFactorys. * + * NgModuleFactory 和一些 ComponentFactory 的组合。 + * * @publicApi */ export class ModuleWithComponentFactories { @@ -88,10 +90,14 @@ const Compiler_compileModuleAndAllComponentsAsync = * to create {@link ComponentFactory}s, which * can later be used to create and render a Component instance. * + * 本底层服务用于供 Angular 编译器在运行期间创建 {@link ComponentFactory},该工厂以后可用于创建和渲染组件实例。 + * * Each `@NgModule` provides an own `Compiler` to its injector, * that will use the directives/pipes of the ng module for compilation * of components. * + * 每个 `@NgModule` 为其注入器提供一个自己的编译器,它将使用此 NgModule 的指令/管道来编译组件。 + * * @publicApi */ @Injectable() @@ -99,39 +105,60 @@ export class Compiler { /** * Compiles the given NgModule and all of its components. All templates of the components listed * in `entryComponents` have to be inlined. + * + * 编译给定的 NgModule 及其所有组件。必须内联 `entryComponents` 列出的组件的所有模板。 + * */ compileModuleSync: (moduleType: Type) => NgModuleFactory = Compiler_compileModuleSync; /** * Compiles the given NgModule and all of its components + * + * 编译给定的 NgModule 及其所有组件 + * */ compileModuleAsync: (moduleType: Type) => Promise> = Compiler_compileModuleAsync; /** * Same as {@link #compileModuleSync} but also creates ComponentFactories for all components. + * + * 与 {@link #compileModuleSync} 相同,但还会为所有组件创建 ComponentFactory。 + * */ compileModuleAndAllComponentsSync: (moduleType: Type) => ModuleWithComponentFactories = Compiler_compileModuleAndAllComponentsSync; /** * Same as {@link #compileModuleAsync} but also creates ComponentFactories for all components. + * + * 与 {@link #compileModuleAsync} 相同,但还会为所有组件创建 ComponentFactory。 + * */ compileModuleAndAllComponentsAsync: (moduleType: Type) => Promise> = Compiler_compileModuleAndAllComponentsAsync; /** * Clears all caches. + * + * 清除所有缓存。 + * */ clearCache(): void {} /** * Clears the cache for the given component/ngModule. + * + * 清除给定组件/ngModule 的缓存。 + * */ clearCacheFor(type: Type) {} /** * Returns the id for a given NgModule, if one is defined and known to the compiler. + * + * 返回给定 NgModule 的 ID(如果已定义且对编译器已知)。 + * */ getModuleId(moduleType: Type): string|undefined { return undefined; @@ -141,6 +168,8 @@ export class Compiler { /** * Options for creating a compiler * + * 用于创建编译器的选项 + * * @publicApi */ export type CompilerOptions = { @@ -154,6 +183,8 @@ export type CompilerOptions = { /** * Token to provide CompilerOptions in the platform injector. * + * 在平台注入器中提供 CompilerOptions 的令牌。 + * * @publicApi */ export const COMPILER_OPTIONS = new InjectionToken('compilerOptions'); @@ -161,6 +192,8 @@ export const COMPILER_OPTIONS = new InjectionToken('compilerO /** * A factory for creating a Compiler * + * 用于创建编译器的工厂 + * * @publicApi */ export abstract class CompilerFactory { diff --git a/packages/core/src/linker/component_factory.ts b/packages/core/src/linker/component_factory.ts index b20fd4184e..fe0be07b68 100644 --- a/packages/core/src/linker/component_factory.ts +++ b/packages/core/src/linker/component_factory.ts @@ -19,50 +19,79 @@ import {ViewRef} from './view_ref'; * Provides access to the component instance and related objects, * and provides the means of destroying the instance. * + * 表示由 `ComponentFactory` 创建的组件。提供对组件实例和相关对象的访问,并提供销毁实例的方法。 + * * @publicApi */ export abstract class ComponentRef { /** * The host or anchor [element](guide/glossary#element) for this component instance. + * + * 此组件实例的宿主或锚点[元素](guide/glossary#element)。 + * */ abstract get location(): ElementRef; /** * The [dependency injector](guide/glossary#injector) for this component instance. + * + * 此组件实例的[依赖项注入器](guide/glossary#injector)。 + * */ abstract get injector(): Injector; /** * This component instance. + * + * 该组件实例。 + * */ abstract get instance(): C; /** * The [host view](guide/glossary#view-tree) defined by the template * for this component instance. + * + * 模板为此组件实例定义的[宿主视图](guide/glossary#view-tree)。 + * */ abstract get hostView(): ViewRef; /** * The change detector for this component instance. + * + * 此组件实例的变更检测器。 + * */ abstract get changeDetectorRef(): ChangeDetectorRef; /** * The type of this component (as created by a `ComponentFactory` class). + * + * 此组件的类型(由 `ComponentFactory` 类创建)。 + * */ abstract get componentType(): Type; /** * Destroys the component instance and all of the data structures associated with it. + * + * 销毁组件实例以及与其关联的所有数据结构。 + * */ abstract destroy(): void; /** * A lifecycle hook that provides additional developer-defined cleanup * functionality for the component. + * + * 一个生命周期钩子,为组件提供其他由开发人员定义的清理功能。 + * * @param callback A handler function that cleans up developer-defined data * associated with this component. Called when the `destroy()` method is invoked. + * + * 一个处理器函数,用于清理与此组件关联的由开发人员定义的数据。在调用 `destroy()` 方法时调用。 + * */ abstract onDestroy(callback: Function): void; } @@ -72,33 +101,55 @@ export abstract class ComponentRef { * Instantiate a factory for a given type of component with `resolveComponentFactory()`. * Use the resulting `ComponentFactory.create()` method to create a component of that type. * + * 可用来动态创建组件的工厂的基类。`resolveComponentFactory()` 实例化给定类型的组件的工厂。使用生成的 `ComponentFactory.create()` 方法创建该类型的组件。 + * * @see [Dynamic Components](guide/dynamic-component-loader) * + * [动态组件](guide/dynamic-component-loader) + * * @publicApi */ export abstract class ComponentFactory { /** * The component's HTML selector. + * + * 组件的 HTML 选择器。 + * */ abstract get selector(): string; /** * The type of component the factory will create. + * + * 工厂将创建的组件的类型。 + * */ abstract get componentType(): Type; /** * Selector for all elements in the component. + * + * 组件中所有 元素的选择器。 + * */ abstract get ngContentSelectors(): string[]; /** * The inputs of the component. + * + * 组件的输入。 + * */ abstract get inputs(): {propName: string, templateName: string}[]; /** * The outputs of the component. + * + * 组件的输出。 + * */ abstract get outputs(): {propName: string, templateName: string}[]; /** * Creates a new component. + * + * 创建一个新组件。 + * */ abstract create( injector: Injector, projectableNodes?: any[][], rootSelectorOrNode?: string|any, diff --git a/packages/core/src/linker/component_factory_resolver.ts b/packages/core/src/linker/component_factory_resolver.ts index 7e8db8891f..5cbbf4f6ea 100644 --- a/packages/core/src/linker/component_factory_resolver.ts +++ b/packages/core/src/linker/component_factory_resolver.ts @@ -39,14 +39,25 @@ class _NullComponentFactoryResolver implements ComponentFactoryResolver { * Use to obtain the factory for a given component type, * then use the factory's `create()` method to create a component of that type. * + * 一个简单的注册表,它将 `Components` 映射到生成的 `ComponentFactory` 类,该类可用于创建组件的实例。用于获取给定组件类型的工厂,然后使用工厂的 `create()` 方法创建该类型的组件。 + * * @see [Dynamic Components](guide/dynamic-component-loader) + * + * [动态组件](guide/dynamic-component-loader) + * * @publicApi */ export abstract class ComponentFactoryResolver { static NULL: ComponentFactoryResolver = new _NullComponentFactoryResolver(); /** * Retrieves the factory object that creates a component of the given type. + * + * 检索能创建给定类型的组件的工厂对象。 + * * @param component The component type. + * + * 组件类型。 + * */ abstract resolveComponentFactory(component: Type): ComponentFactory; } diff --git a/packages/core/src/linker/ng_module_factory.ts b/packages/core/src/linker/ng_module_factory.ts index 05e4c430e0..96b39cc566 100644 --- a/packages/core/src/linker/ng_module_factory.ts +++ b/packages/core/src/linker/ng_module_factory.ts @@ -16,32 +16,49 @@ import {ComponentFactoryResolver} from './component_factory_resolver'; * Represents an instance of an `NgModule` created by an `NgModuleFactory`. * Provides access to the `NgModule` instance and related objects. * + * `NgModule` 创建的 `NgModuleFactory` 的实例。提供对 `NgModule` 实例和相关对象的访问。 + * * @publicApi */ export abstract class NgModuleRef { /** * The injector that contains all of the providers of the `NgModule`. + * + * 包含 `NgModule` 所有提供者的注入器。 + * */ abstract get injector(): Injector; /** * The resolver that can retrieve the component factories * declared in the `entryComponents` property of the module. + * + * 此解析器可以检索本模块的 `entryComponents` 属性中声明的组件工厂。 + * */ abstract get componentFactoryResolver(): ComponentFactoryResolver; /** * The `NgModule` instance. + * + * `NgModule` 实例。 + * */ abstract get instance(): T; /** * Destroys the module instance and all of the data structures associated with it. + * + * 销毁模块实例以及与其关联的所有数据结构。 + * */ abstract destroy(): void; /** * Registers a callback to be executed when the module is destroyed. + * + * 注册一个销毁模块时要执行的回调。 + * */ abstract onDestroy(callback: () => void): void; } diff --git a/packages/core/src/linker/ng_module_factory_loader.ts b/packages/core/src/linker/ng_module_factory_loader.ts index 1586a4418c..bda867acd6 100644 --- a/packages/core/src/linker/ng_module_factory_loader.ts +++ b/packages/core/src/linker/ng_module_factory_loader.ts @@ -16,9 +16,14 @@ import {getRegisteredNgModuleType} from './ng_module_factory_registration'; /** * Used to load ng module factories. * + * 用来加载 ng 模块工厂。 + * * @publicApi * @deprecated the `string` form of `loadChildren` is deprecated, and `NgModuleFactoryLoader` is * part of its implementation. See `LoadChildren` for more details. + * + * 不建议使用 `loadChildren` 的 `string` 形式,`NgModuleFactoryLoader` 是其实现的一部分。欲知详情,请参见 `LoadChildren` + * */ export abstract class NgModuleFactoryLoader { abstract load(path: string): Promise>; @@ -40,6 +45,9 @@ export function getModuleFactory__POST_R3__(id: string): NgModuleFactory { * Returns the NgModuleFactory with the given id, if it exists and has been loaded. * Factories for modules that do not specify an `id` cannot be retrieved. Throws if the module * cannot be found. + * + * 返回具有给定 id 的 NgModuleFactory(如果存在并且已加载)。无法检索未指定过 `id` 的模块工厂。如果找不到模块,则抛出该异常。 + * * @publicApi */ export const getModuleFactory: (id: string) => NgModuleFactory = getModuleFactory__PRE_R3__; diff --git a/packages/core/src/linker/ng_module_factory_registration.ts b/packages/core/src/linker/ng_module_factory_registration.ts index 2462d86b1b..2ca0565b3e 100644 --- a/packages/core/src/linker/ng_module_factory_registration.ts +++ b/packages/core/src/linker/ng_module_factory_registration.ts @@ -25,6 +25,9 @@ const modules = new Map|NgModuleType>(); /** * Registers a loaded module. Should only be called from generated NgModuleFactory code. + * + * 注册已加载的模块。仅应从生成的 NgModuleFactory 代码中调用。 + * * @publicApi */ export function registerModuleFactory(id: string, factory: NgModuleFactory) { diff --git a/packages/core/src/linker/query_list.ts b/packages/core/src/linker/query_list.ts index 6429e096da..8d160dcee3 100644 --- a/packages/core/src/linker/query_list.ts +++ b/packages/core/src/linker/query_list.ts @@ -42,6 +42,7 @@ function symbolIterator(this: QueryList): Iterator { * 注意:将来此类将会实现 `Observable` 接口。 * * @usageNotes + * * ### Example * * ### 例子 @@ -78,6 +79,9 @@ export class QueryList implements Iterable { /** * Returns the QueryList entry at `index`. + * + * 返回位于 `index` 处的 QueryList 条目。 + * */ get(index: number): T|undefined { return this._results[index]; @@ -145,6 +149,9 @@ export class QueryList implements Iterable { /** * Returns a copy of the internal results list as an Array. + * + * 以数组形式返回内部结果列表的副本。 + * */ toArray(): T[] { return this._results.slice(); @@ -159,7 +166,11 @@ export class QueryList implements Iterable { * on change detection, it will not notify of changes to the queries, unless a new change * occurs. * + * 更新查询列表中存储的数据,并将 `dirty` 标志重置为 `false`,以便当检测到变更时,除非发生新变更,否则不会通知这些查询的变更。 + * * @param resultsTree The query results to store + * + * 要存储的查询结果 */ reset(resultsTree: Array): void { this._results = flatten(resultsTree); @@ -171,6 +182,9 @@ export class QueryList implements Iterable { /** * Triggers a change event by emitting on the `changes` {@link EventEmitter}. + * + * 通过发出 `changes` {@link EventEmitter} 来触发变更事件。 + * */ notifyOnChanges(): void { (this.changes as EventEmitter).emit(this); diff --git a/packages/core/src/linker/system_js_ng_module_factory_loader.ts b/packages/core/src/linker/system_js_ng_module_factory_loader.ts index 625467febd..5052f0ecd4 100644 --- a/packages/core/src/linker/system_js_ng_module_factory_loader.ts +++ b/packages/core/src/linker/system_js_ng_module_factory_loader.ts @@ -23,19 +23,30 @@ declare var System: any; * Configuration for SystemJsNgModuleLoader. * token. * + * SystemJsNgModuleLoader 的配置。令牌。 + * * @publicApi * @deprecated the `string` form of `loadChildren` is deprecated, and `SystemJsNgModuleLoaderConfig` * is part of its implementation. See `LoadChildren` for more details. + * + * 不推荐使用 `loadChildren` 的 `string` 形式 `SystemJsNgModuleLoaderConfig` 是其实现的一部分。有关更多详细信息,请参见 `LoadChildren` + * */ export abstract class SystemJsNgModuleLoaderConfig { /** * Prefix to add when computing the name of the factory module for a given module name. + * + * 计算给定模块名称的工厂模块名称时添加的前缀。 + * */ // TODO(issue/24571): remove '!'. factoryPathPrefix!: string; /** * Suffix to add when computing the name of the factory module for a given module name. + * + * 计算给定模块名称的工厂模块名称时添加的后缀。 + * */ // TODO(issue/24571): remove '!'. factoryPathSuffix!: string; @@ -48,9 +59,15 @@ const DEFAULT_CONFIG: SystemJsNgModuleLoaderConfig = { /** * NgModuleFactoryLoader that uses SystemJS to load NgModuleFactory + * + * 使用 SystemJS 加载 NgModuleFactory 的 NgModuleFactoryLoader + * * @publicApi * @deprecated the `string` form of `loadChildren` is deprecated, and `SystemJsNgModuleLoader` is * part of its implementation. See `LoadChildren` for more details. + * + * 该 `string` 的形式 `loadChildren` 已被弃用, `SystemJsNgModuleLoader` 是其实现的一部分。有关更多详细信息,请参见 `LoadChildren` + * */ @Injectable() export class SystemJsNgModuleLoader implements NgModuleFactoryLoader { diff --git a/packages/core/src/linker/view_container_ref.ts b/packages/core/src/linker/view_container_ref.ts index 6ae039aff7..1e11d47925 100644 --- a/packages/core/src/linker/view_container_ref.ts +++ b/packages/core/src/linker/view_container_ref.ts @@ -88,7 +88,12 @@ export abstract class ViewContainerRef { */ abstract get injector(): Injector; - /** @deprecated No replacement */ + /** + * @deprecated No replacement + * + * 无替代品 + * + */ abstract get parentInjector(): Injector; /** diff --git a/packages/core/src/linker/view_ref.ts b/packages/core/src/linker/view_ref.ts index bafc35a488..11c9611567 100644 --- a/packages/core/src/linker/view_ref.ts +++ b/packages/core/src/linker/view_ref.ts @@ -11,6 +11,8 @@ import {ChangeDetectorRef} from '../change_detection/change_detector_ref'; /** * Represents an Angular [view](guide/glossary#view "Definition"). * + * 表示一个 Angular [视图](guide/glossary#view "Definition")。 + * * @see {@link ChangeDetectorRef#usage-notes Change detection usage} * * @publicApi @@ -18,20 +20,35 @@ import {ChangeDetectorRef} from '../change_detection/change_detector_ref'; export abstract class ViewRef extends ChangeDetectorRef { /** * Destroys this view and all of the data structures associated with it. + * + * 销毁该视图以及与之关联的所有数据结构。 + * */ abstract destroy(): void; /** * Reports whether this view has been destroyed. + * + * 报告此视图是否已被销毁。 + * * @returns True after the `destroy()` method has been called, false otherwise. + * + * 调用 `destroy()` 方法后为 true,否则为 false。 + * */ abstract get destroyed(): boolean; /** * A lifecycle hook that provides additional developer-defined cleanup * functionality for views. + * + * 生命周期钩子,为视图提供其他由开发人员定义的清理功能。 + * * @param callback A handler function that cleans up developer-defined data * associated with a view. Called when the `destroy()` method is invoked. + * + * 处理函数,用于清理与视图关联的由开发人员定义的数据。在调用 `destroy()` 方法时调用。 + * */ abstract onDestroy(callback: Function): any /** TODO #9100 */; } @@ -42,10 +59,14 @@ export abstract class ViewRef extends ChangeDetectorRef { * other than the hosting component whose template defines it, or it can be defined * independently by a `TemplateRef`. * + * 表示视图容器中的 Angular [视图](guide/glossary#view)。[嵌入视图](guide/glossary#view-tree)可以从在模板中定义它的宿主组件之外的组件中引用,也可以由 `TemplateRef` 进行独立定义。 + * * Properties of elements in a view can change, but the structure (number and order) of elements in * a view cannot. Change the structure of elements by inserting, moving, or * removing nested views in a view container. * + * 视图中元素的属性可以更改,但是视图中元素的结构(数量和顺序)不能更改。通过在视图容器中插入,移动或删除嵌套视图来更改元素的结构。 + * * @see `ViewContainerRef` * * @usageNotes @@ -53,6 +74,8 @@ export abstract class ViewRef extends ChangeDetectorRef { * The following template breaks down into two separate `TemplateRef` instances, * an outer one and an inner one. * + * 以下模板分为两个单独的 `TemplateRef` 实例,一个外部实例和一个内部实例。 + * * ``` * Count: {{items.length}} *
      @@ -62,6 +85,8 @@ export abstract class ViewRef extends ChangeDetectorRef { * * This is the outer `TemplateRef`: * + * 这是外部 `TemplateRef` : + * * ``` * Count: {{items.length}} *
        @@ -71,12 +96,16 @@ export abstract class ViewRef extends ChangeDetectorRef { * * This is the inner `TemplateRef`: * + * 这是内部的 `TemplateRef` : + * * ``` *
      • {{item}}
      • * ``` * * The outer and inner `TemplateRef` instances are assembled into views as follows: * + * 外部和内部 `TemplateRef` 实例按如下方式组装到视图中: + * * ``` * * Count: 2 @@ -92,11 +121,17 @@ export abstract class ViewRef extends ChangeDetectorRef { export abstract class EmbeddedViewRef extends ViewRef { /** * The context for this view, inherited from the anchor element. + * + * 该视图的上下文,继承自锚点元素。 + * */ abstract get context(): C; /** * The root nodes for this embedded view. + * + * 此嵌入式视图的根节点。 + * */ abstract get rootNodes(): any[]; } diff --git a/packages/core/src/metadata/di.ts b/packages/core/src/metadata/di.ts index 2efba89892..3f60a7ee28 100644 --- a/packages/core/src/metadata/di.ts +++ b/packages/core/src/metadata/di.ts @@ -17,12 +17,16 @@ import {makePropDecorator} from '../util/decorators'; * All components that are referenced in the `useValue` value (either directly * or in a nested array or map) are added to the `entryComponents` property. * + * 可用于创建虚拟[提供者](guide/glossary#provider)的 DI 令牌,该虚拟提供者将基于其 `useValue` 属性值填充组件和 NgModule 的 `entryComponents` 字段。`useValue` 值中引用的所有组件(无论是直接还是在嵌套数组还是在映射表中)都将添加到 `entryComponents` 属性。 + * * @usageNotes * * The following example shows how the router can populate the `entryComponents` * field of an NgModule based on a router configuration that refers * to components. * + * 以下示例演示了路由器如何基于引用组件的路由器配置设置 `entryComponents` 字段。 + * * ```typescript * // helper function inside the router * function provideRoutes(routes) { @@ -46,30 +50,42 @@ import {makePropDecorator} from '../util/decorators'; * * @publicApi * @deprecated Since 9.0.0. With Ivy, this property is no longer necessary. + * + * 从 9.0.0 开始。使用 Ivy,不再需要此属性。 */ export const ANALYZE_FOR_ENTRY_COMPONENTS = new InjectionToken('AnalyzeForEntryComponents'); /** * Type of the `Attribute` decorator / constructor function. * + * `Attribute` 装饰器/构造函数的类型。 + * * @publicApi */ export interface AttributeDecorator { /** * Specifies that a constant attribute value should be injected. * + * 指定应注入的常量属性值。 + * * The directive can inject constant string literals of host element attributes. * + * 该指令可以注入宿主元素属性的字符串字面常量。 + * * @usageNotes * * Suppose we have an `` element and want to know its `type`. * + * 假设我们有一个 `` 元素,并且想知道它的 `type` 。 + * * ```html * * ``` * * A decorator can inject string literal `text` as in the following example. * + * 装饰器可以注入字符串字面量 `text` ,如下面的例子。 + * * {@example core/ts/metadata/metadata.ts region='attributeMetadata'} * * @publicApi @@ -82,11 +98,16 @@ export interface AttributeDecorator { /** * Type of the Attribute metadata. * + * 属性元数据的类型。 + * * @publicApi */ export interface Attribute { /** * The name of the attribute to be injected into the constructor. + * + * 要注入到构造函数中的属性的名称。 + * */ attributeName?: string; } @@ -94,6 +115,8 @@ export interface Attribute { /** * Type of the Query metadata. * + * 查询元数据的类型。 + * * @publicApi */ export interface Query { @@ -108,6 +131,8 @@ export interface Query { /** * Base class for query metadata. * + * 查询元数据的基类。 + * * @see `ContentChildren`. * @see `ContentChild`. * @see `ViewChildren`. @@ -120,6 +145,8 @@ export abstract class Query {} /** * Type of the ContentChildren decorator / constructor function. * + * ContentChildren 装饰器/构造函数的类型。 + * * @see `ContentChildren`. * @publicApi */ @@ -127,25 +154,45 @@ export interface ContentChildrenDecorator { /** * Parameter decorator that configures a content query. * + * 用于配置内容查询的参数装饰器。 + * * Use to get the `QueryList` of elements or directives from the content DOM. * Any time a child element is added, removed, or moved, the query list will be * updated, and the changes observable of the query list will emit a new value. * + * 用于从内容 DOM 中获取元素或指令的 `QueryList`。每当添加、删除或移动子元素时,此查询列表都会更新,并且其可观察对象 changes 都会发出新值。 + * * Content queries are set before the `ngAfterContentInit` callback is called. * + * 在调用 `ngAfterContentInit` 回调之前设置的内容查询。 + * * Does not retrieve elements or directives that are in other components' templates, * since a component's template is always a black box to its ancestors. * + * 不检索其他组件模板中的元素或指令,因为组件模板对其祖先来说始终是黑匣子。 + * * **Metadata Properties**: * + * **元数据属性**: + * * * **selector** - The directive type or the name used for querying. + * + * **selector** - 要查询的指令类型或名称。 + * * * **descendants** - True to include all descendants, otherwise include only direct children. + * + * **后代** - 包含所有后代时为 true,否则仅包括直接子代。 + * * * **read** - Used to read a different token from the queried elements. * + * **read** - 用于从查询到的元素中读取不同的令牌。 + * * @usageNotes * * Here is a simple demonstration of how the `ContentChildren` decorator can be used. * + * 这里是如何使用 `ContentChildren` 装饰器的简单演示。 + * * {@example core/di/ts/contentChildren/content_children_howto.ts region='HowTo'} * * ### Tab-pane example @@ -166,6 +213,7 @@ export interface ContentChildrenDecorator { /** * Type of the ContentChildren metadata. * + * ContentChildren 元数据的类型。 * * @Annotation * @publicApi @@ -175,6 +223,7 @@ export type ContentChildren = Query; /** * ContentChildren decorator and metadata. * + * ContentChildren 装饰器和元数据。 * * @Annotation * @publicApi @@ -188,28 +237,47 @@ export const ContentChildren: ContentChildrenDecorator = makePropDecorator( /** * Type of the ContentChild decorator / constructor function. * + * ContentChild 装饰器/构造函数的类型。 + * * @publicApi */ export interface ContentChildDecorator { /** * Parameter decorator that configures a content query. * + * 用于配置内容查询的参数装饰器。 + * * Use to get the first element or the directive matching the selector from the content DOM. * If the content DOM changes, and a new child matches the selector, * the property will be updated. * + * 用于从内容 DOM 获取与此选择器匹配的第一个元素或指令。如果内容 DOM 发生了更改,并且有一个新的子项与选择器匹配,则该属性将被更新。 + * * Content queries are set before the `ngAfterContentInit` callback is called. * + * 在调用 `ngAfterContentInit` 之前设置的内容查询。 + * * Does not retrieve elements or directives that are in other components' templates, * since a component's template is always a black box to its ancestors. * + * 不检索其他组件模板中的元素或指令,因为组件模板对其祖先来说始终是黑匣子。 + * * **Metadata Properties**: * + * **元数据属性**: + * * * **selector** - The directive type or the name used for querying. + * + * **selector** - 要查询的指令类型或名称。 + * * * **read** - Used to read a different token from the queried element. + * + * **read** - 用于从查询到的元素读取不同的令牌。 + * * * **static** - True to resolve query results before change detection runs, * false to resolve after change detection. Defaults to false. * + * **static** - 如果为 true,则在变更检测运行之前解析查询结果,如果为 false,则在变更检测之后解析。默认为 false。 * @usageNotes * * {@example core/di/ts/contentChild/content_child_howto.ts region='HowTo'} @@ -229,6 +297,8 @@ export interface ContentChildDecorator { /** * Type of the ContentChild metadata. * + * ContentChild 元数据的类型。 + * * @publicApi */ export type ContentChild = Query; @@ -236,6 +306,7 @@ export type ContentChild = Query; /** * ContentChild decorator and metadata. * + * ContentChild 装饰器和元数据。 * * @Annotation * @@ -250,6 +321,8 @@ export const ContentChild: ContentChildDecorator = makePropDecorator( /** * Type of the ViewChildren decorator / constructor function. * + * ViewChildren 装饰器/构造函数的类型。 + * * @see `ViewChildren`. * * @publicApi @@ -258,17 +331,29 @@ export interface ViewChildrenDecorator { /** * Parameter decorator that configures a view query. * + * 用于配置视图查询的参数装饰器。 + * * Use to get the `QueryList` of elements or directives from the view DOM. * Any time a child element is added, removed, or moved, the query list will be updated, * and the changes observable of the query list will emit a new value. * + * 用于从视图 DOM 中获取元素或指令的 `QueryList`。每当添加、删除或移动子元素时,此查询列表都将更新,并且其可观察对象 changes 将发出新值。 + * * View queries are set before the `ngAfterViewInit` callback is called. * + * 在调用 `ngAfterViewInit` 前设置的视图查询。 + * * **Metadata Properties**: * + * **元数据属性**: + * * * **selector** - The directive type or the name used for querying. + * + * **selector** - 要查询的指令类型或名称。 + * * * **read** - Used to read a different token from the queried elements. * + * **read** - 用于从查询的元素中读取不同的令牌。 * @usageNotes * * {@example core/di/ts/viewChildren/view_children_howto.ts region='HowTo'} @@ -287,6 +372,8 @@ export interface ViewChildrenDecorator { /** * Type of the ViewChildren metadata. * + * ViewChildren 元数据的类型。 + * * @publicApi */ export type ViewChildren = Query; @@ -294,6 +381,8 @@ export type ViewChildren = Query; /** * ViewChildren decorator and metadata. * + * ViewChildren 装饰器和元数据。 + * * @Annotation * @publicApi */ @@ -342,6 +431,8 @@ export interface ViewChildDecorator { * * **static** - True to resolve query results before change detection runs, * false to resolve after change detection. Defaults to false. * + * **static** - 如果为 true,则在变更检测运行之前解析查询结果,如果为 false,则在变更检测之后解析。默认为 false。 + * * The following selectors are supported. * * 支持下列选择器: @@ -358,13 +449,13 @@ export interface ViewChildDecorator { * * Any provider defined in the child component tree of the current component (e.g. * `@ViewChild(SomeService) someService: SomeService`) * - * 组件树中任何当前组件的子组件所定义的提供商(比如 `@ViewChild(SomeService) someService: SomeService` ) + * 组件树中任何当前组件的子组件所定义的提供者(比如 `@ViewChild(SomeService) someService: SomeService` ) * * * Any provider defined through a string token (e.g. `@ViewChild('someToken') someTokenVal: * any`) * - * 任何通过字符串令牌定义的提供商(比如 `@ViewChild('someToken') someTokenVal: - * any` ) + * 任何通过字符串令牌定义的提供者(比如 `@ViewChild('someToken') someTokenVal: + * any`) * * * A `TemplateRef` (e.g. query `` with `@ViewChild(TemplateRef) * template;`) diff --git a/packages/core/src/metadata/directives.ts b/packages/core/src/metadata/directives.ts index e4593ca966..c4f50373ae 100644 --- a/packages/core/src/metadata/directives.ts +++ b/packages/core/src/metadata/directives.ts @@ -30,6 +30,8 @@ export interface DirectiveDecorator { * Decorator that marks a class as an Angular directive. * You can define your own directives to attach custom behavior to elements in the DOM. * + * 将类标记为 Angular 指令的装饰器。你可以定义自己的指令,以将自定义行为附加到 DOM 中的元素。 + * * The options provide configuration metadata that determines * how the directive should be processed, instantiated and used at * runtime. @@ -44,6 +46,7 @@ export interface DirectiveDecorator { * * * @usageNotes + * * To define a directive, mark the class with the decorator and provide metadata. * * 要想定义一个指令,请为该类加上此装饰器,并提供元数据。 @@ -99,6 +102,8 @@ export interface DirectiveDecorator { /** * Directive decorator and metadata. * + * 指令装饰器和元数据。 + * * @Annotation * @publicApi */ @@ -302,7 +307,6 @@ export interface Directive { * View queries are set before the `ngAfterViewInit` callback is called. * * 内容查询会在调用 `ngAfterContentInit` 回调之前设置好。 - * 试图查询会在调用 `ngAfterViewInit` 回调之前设置好。 * * @usageNotes * @@ -387,6 +391,9 @@ export interface Directive { * It remains in distributed code, and the JIT compiler attempts to compile it * at run time, in the browser. * To ensure the correct behavior, the app must import `@angular/compiler`. + * + * 如果存在,则该指令/组件将被 AOT 编译器忽略。它会保留在发布代码中,并且 JIT 编译器会尝试在运行时在浏览器中对其进行编译。为了确保其行为正确,该应用程序必须导入 `@angular/compiler` 。 + * */ jit?: true; } @@ -470,12 +477,12 @@ export interface ComponentDecorator { * * ### Injecting a class with a view provider * - * ### 使用视图提供商注入一个类 + * ### 使用视图提供者注入一个类 * * The following simple example injects a class into a component * using the view provider specified in component metadata: * - * 下面的例子示范了如何在组件元数据中使用视图提供商来把一个类注入到组件中: + * 下面的例子示范了如何在组件元数据中使用视图提供者来把一个类注入到组件中: * * ```ts * class Greeter { @@ -684,6 +691,9 @@ export interface Component extends Directive { * * - `ViewEncapsulation.None`: Use global CSS without any * encapsulation. + * + * `ViewEncapsulation.None` :使用不带任何封装的全局 CSS。 + * * - `ViewEncapsulation.ShadowDom`: Use Shadow DOM v1 to encapsulate styles. * * `ViewEncapsulation.None`:使用全局 CSS,不做任何封装。 @@ -716,6 +726,9 @@ export interface Component extends Directive { * 一个组件的集合,它应该和当前组件一起编译。对于这里列出的每个组件,Angular 都会创建一个 {@link ComponentFactory} 并保存进 {@link ComponentFactoryResolver} 中。 * * @deprecated Since 9.0.0. With Ivy, this property is no longer necessary. + * + * 从 9.0.0 开始。使用 Ivy,不再需要此属性。 + * */ entryComponents?: Array|any[]>; @@ -756,22 +769,32 @@ export interface PipeDecorator { * * Decorator that marks a class as pipe and supplies configuration metadata. * + * 本装饰器用于将类标记为管道并提供配置元数据。 + * * A pipe class must implement the `PipeTransform` interface. * For example, if the name is "myPipe", use a template binding expression * such as the following: * + * 管道类必须实现 `PipeTransform` 接口。例如,如果其名称为 “myPipe”,则使用模板绑定表达式,例如: + * * ``` * {{ exp | myPipe }} * ``` * * The result of the expression is passed to the pipe's `transform()` method. * + * 此表达式的结果会传给管道的 `transform()` 方法。 + * * A pipe must belong to an NgModule in order for it to be available * to a template. To make it a member of an NgModule, * list it in the `declarations` field of the `NgModule` metadata. * + * 管道必须属于某个 NgModule,才能用于模板。要使其成为 NgModule 的成员,请把它加入 `NgModule` 元数据的 `declarations` 中。 + * * @see [Style Guide: Pipe Names](guide/styleguide#02-09) * + * [样式指南:管道名称](guide/styleguide#02-09) + * */ (obj: Pipe): TypeDecorator; @@ -884,6 +907,8 @@ export interface InputDecorator { * ``` * * @see [Input and Output properties](guide/inputs-outputs) + * + * [输入和输出属性](guide/inputs-outputs) */ (bindingPropertyName?: string): any; new(bindingPropertyName?: string): any; @@ -944,6 +969,8 @@ export interface OutputDecorator { * * @see [Input and Output properties](guide/inputs-outputs) * + * [输入和输出属性](guide/inputs-outputs) + * */ (bindingPropertyName?: string): any; new(bindingPropertyName?: string): any; @@ -959,6 +986,9 @@ export interface OutputDecorator { export interface Output { /** * The name of the DOM property to which the output property is bound. + * + * 输出属性绑定到的 DOM 属性的名称。 + * */ bindingPropertyName?: string; } @@ -1029,6 +1059,9 @@ export interface HostBindingDecorator { export interface HostBinding { /** * The DOM property that is bound to a data property. + * + * 要绑定到数据属性的 DOM 属性。 + * */ hostPropertyName?: string; } @@ -1052,6 +1085,9 @@ export interface HostListenerDecorator { /** * Decorator that declares a DOM event to listen for, * and provides a handler method to run when that event occurs. + * + * 一个装饰器,用于声明要监听的 DOM 事件,并提供在该事件发生时要运行的处理器方法。 + * */ (eventName: string, args?: string[]): any; new(eventName: string, args?: string[]): any; @@ -1084,6 +1120,8 @@ export interface HostListener { * Angular invokes the supplied handler method when the host element emits the specified event, * and updates the bound element with the result. * + * 将 DOM 事件绑定到宿主监听器并提供配置元数据的装饰器。当宿主元素发出指定事件时,Angular 就会调用所提供的处理器方法,并使用其结果更新绑定的元素。 + * * If the handler method returns false, applies `preventDefault` on the bound element. * * 把一个事件绑定到一个宿主监听器,并提供配置元数据。 diff --git a/packages/core/src/metadata/do_boostrap.ts b/packages/core/src/metadata/do_boostrap.ts index 17190fceb2..c7715a31c6 100644 --- a/packages/core/src/metadata/do_boostrap.ts +++ b/packages/core/src/metadata/do_boostrap.ts @@ -14,11 +14,14 @@ import {ApplicationRef} from '../application_ref'; * Hook for manual bootstrapping of the application instead of using bootstrap array in @NgModule * annotation. * + * 挂钩以手动引导应用程序,而不是在 @NgModule 标记中的 bootstrap 数组。 + * * Reference to the current application is provided as a parameter. * * See ["Bootstrapping"](guide/bootstrapping) and ["Entry components"](guide/entry-components). * * @usageNotes + * * ```typescript * class AppModule implements DoBootstrap { * ngDoBootstrap(appRef: ApplicationRef) { diff --git a/packages/core/src/metadata/ng_module.ts b/packages/core/src/metadata/ng_module.ts index 2b25352f39..1ab17ab2bc 100644 --- a/packages/core/src/metadata/ng_module.ts +++ b/packages/core/src/metadata/ng_module.ts @@ -31,6 +31,8 @@ export type ɵɵNgModuleDefWithMeta = NgModul * * @see [Deprecations](guide/deprecations#modulewithproviders-type-without-a-generic) * + * [弃用](guide/deprecations#modulewithproviders-type-without-a-generic) + * * @publicApi */ export interface ModuleWithProviders { @@ -72,8 +74,13 @@ export interface NgModule { * 在当前模块的注入器中可用的一组可注入对象。 * * @see [Dependency Injection guide](guide/dependency-injection) + * + * [依赖注入指南](guide/dependency-injection) + * * @see [NgModule guide](guide/providers) * + * [NgModule 指南](guide/providers) + * * @usageNotes * * Dependencies whose providers are listed here become available for injection @@ -81,7 +88,7 @@ export interface NgModule { * The NgModule used for bootstrapping uses the root injector, and can provide dependencies * to any part of the app. * - * 在这里列出了提供商的依赖项可用于注入到任何组件、指令、管道或该注入器下的服务。 + * 在这里列出了提供者的依赖项可用于注入到任何组件、指令、管道或该注入器下的服务。 * 引导用的 NgModule 使用的是根注入器,可以为应用中的任何部件提供依赖。 * * A lazy-loaded module has its own injector, typically a child of the app root injector. @@ -274,7 +281,13 @@ export interface NgModule { * 该选项用于添加那些需要写代码来创建的组件,比如 `ViewContainerRef.createComponent()`。 * * @see [Entry Components](guide/entry-components) + * + * [入口组件](guide/entry-components) + * * @deprecated Since 9.0.0. With Ivy, this property is no longer necessary. + * + * 从 9.0.0 开始。使用 Ivy,不再需要此属性。 + * */ entryComponents?: Array|any[]>; @@ -321,6 +334,9 @@ export interface NgModule { * It remains in distributed code, and the JIT compiler attempts to compile it * at run time, in the browser. * To ensure the correct behavior, the app must import `@angular/compiler`. + * + * 如果存在,则该指令/组件将被 AOT 编译器忽略。它会保留在发布代码中,并且 JIT 编译器会尝试在运行时在浏览器中对其进行编译。为了确保其行为正确,该应用程序必须导入 `@angular/compiler` 。 + * */ jit?: true; } diff --git a/packages/core/src/metadata/schema.ts b/packages/core/src/metadata/schema.ts index 9850f69ac0..41d9c99ac2 100644 --- a/packages/core/src/metadata/schema.ts +++ b/packages/core/src/metadata/schema.ts @@ -10,10 +10,14 @@ /** * A schema definition associated with an NgModule. * + * 与 NgModule 关联的架构定义。 + * * @see `@NgModule`, `CUSTOM_ELEMENTS_SCHEMA`, `NO_ERRORS_SCHEMA` * * @param name The name of a defined schema. * + * 定义的架构的名称。 + * * @publicApi */ export interface SchemaMetadata { @@ -22,10 +26,18 @@ export interface SchemaMetadata { /** * Defines a schema that allows an NgModule to contain the following: + * + * 定义一个架构,该架构允许 NgModule 包含以下内容: + * * - Non-Angular elements named with dash case (`-`). + * + * 使用(`-`)命名法的非 Angular 元素。 + * * - Element properties named with dash case (`-`). * Dash case is the naming convention for custom elements. * + * 使用(`-`)命名的元素属性。中线命名法是自定义元素的命名约定。 + * * @publicApi */ export const CUSTOM_ELEMENTS_SCHEMA: SchemaMetadata = { @@ -35,6 +47,8 @@ export const CUSTOM_ELEMENTS_SCHEMA: SchemaMetadata = { /** * Defines a schema that allows any property on any element. * + * 定义一个架构,该架构允许任何元素上的任何属性。 + * * @publicApi */ export const NO_ERRORS_SCHEMA: SchemaMetadata = { diff --git a/packages/core/src/metadata/view.ts b/packages/core/src/metadata/view.ts index d8295d2b16..4010d32b88 100644 --- a/packages/core/src/metadata/view.ts +++ b/packages/core/src/metadata/view.ts @@ -9,11 +9,18 @@ /** * Defines template and style encapsulation options available for Component's {@link Component}. * + * 定义可用于 Component 的 {@link Component} 的模板和样式封装选项。 + * * See {@link Component#encapsulation encapsulation}. * + * 请参阅 {@link Component#encapsulation encapsulation}。 + * * @usageNotes + * * ### Example * + * ### 例子 + * * {@example core/ts/metadata/encapsulation.ts region='longform'} * * @publicApi @@ -25,7 +32,11 @@ export enum ViewEncapsulation { * {@link Component#styleUrls styleUrls}, and adding the new Host Element attribute to all * selectors. * + * 通过向宿主元素添加包含替代 ID 的属性并预处理通过 {@link Component#styles styles} 或 {@link Component#styleUrls styleUrls} 提供的样式规则,来模拟 `Native` 所有选择器。 + * * This is the default option. + * + * 这是默认选项。 */ Emulated = 0, @@ -33,15 +44,23 @@ export enum ViewEncapsulation { /** * Don't provide any template or style encapsulation. + * + * 不要提供任何模板或样式封装。 + * */ None = 2, /** * Use Shadow DOM to encapsulate styles. * + * 使用 Shadow DOM 封装样式。 + * * For the DOM this means using modern [Shadow * DOM](https://w3c.github.io/webcomponents/spec/shadow/) and * creating a ShadowRoot for Component's Host Element. + * + * 对于 DOM,这意味着使用现代的 [Shadow DOM](https://w3c.github.io/webcomponents/spec/shadow/) 并为组件的 Host 元素创建 ShadowRoot。 + * */ ShadowDom = 3 } diff --git a/packages/core/src/platform_core_providers.ts b/packages/core/src/platform_core_providers.ts index 1324e4df67..a8947e2ded 100644 --- a/packages/core/src/platform_core_providers.ts +++ b/packages/core/src/platform_core_providers.ts @@ -23,6 +23,8 @@ const _CORE_PLATFORM_PROVIDERS: StaticProvider[] = [ /** * This platform has to be included in any other platform * + * 任何其他平台都必须包含此平台 + * * @publicApi */ export const platformCore = createPlatformFactory(null, 'core', _CORE_PLATFORM_PROVIDERS); diff --git a/packages/core/src/render/api.ts b/packages/core/src/render/api.ts index 50d8078220..313ef9200d 100644 --- a/packages/core/src/render/api.ts +++ b/packages/core/src/render/api.ts @@ -22,27 +22,53 @@ export const Renderer2Interceptor = new InjectionToken('Renderer2In /** * Creates and initializes a custom renderer that implements the `Renderer2` base class. * + * 创建并初始化实现 `Renderer2` 基类的自定义渲染器。 + * * @publicApi */ export abstract class RendererFactory2 { /** * Creates and initializes a custom renderer for a host DOM element. + * + * 为宿主 DOM 元素创建并初始化自定义渲染器。 + * * @param hostElement The element to render. + * + * 要渲染的元素。 + * * @param type The base class to implement. + * + * 要实现的基类。 + * * @returns The new custom renderer instance. + * + * 新的自定义渲染器实例。 + * */ abstract createRenderer(hostElement: any, type: RendererType2|null): Renderer2; /** * A callback invoked when rendering has begun. + * + * 渲染开始时调用的回调。 + * */ abstract begin?(): void; /** * A callback invoked when rendering has completed. + * + * 渲染完成时调用的回调。 + * */ abstract end?(): void; /** * Use with animations test-only mode. Notifies the test when rendering has completed. + * + * 与动画的“仅测试”模式一起使用。渲染完成后通知该测试。 + * * @returns The asynchronous result of the developer-defined function. + * + * 由开发人员定义函数的异步结果。 + * */ abstract whenRenderingDone?(): Promise; } @@ -182,6 +208,9 @@ export abstract class Renderer2 { * would always assume that any `insertBefore` is a move. This is not strictly true because * with runtime i18n it is possible to invoke `insertBefore` as a result of i18n and it should * not trigger an animation move. + * + * 可选参数,指示当前的 `insertBefore` 是否是移动的结果。动画使用此信息来触发移动动画。过去,Animation 始终假定任何 `insertBefore` 都是一次移动。但严格来说这是不正确的,因为在支持 i18n 的运行环境中,可以调用 `insertBefore`,而不应触发移动动画。 + * */ abstract insertBefore(parent: any, newChild: any, refChild: any, isMove?: boolean): void; /** diff --git a/packages/core/src/render/api_flags.ts b/packages/core/src/render/api_flags.ts index 486a55260b..b556114f97 100644 --- a/packages/core/src/render/api_flags.ts +++ b/packages/core/src/render/api_flags.ts @@ -12,32 +12,59 @@ import {ViewEncapsulation} from '../metadata/view'; /** * Used by `RendererFactory2` to associate custom rendering data and styles * with a rendering implementation. + * + * 供 `RendererFactory2` 用于将自定义渲染数据和样式与某个渲染器的实现相关联。 + * * @publicApi */ export interface RendererType2 { /** * A unique identifying string for the new renderer, used when creating * unique styles for encapsulation. + * + * 创建新的封装样式时使用的新渲染器的唯一标识字符串。 + * */ id: string; /** * The view encapsulation type, which determines how styles are applied to * DOM elements. One of + * + * 视图封装类型,它确定如何将样式应用于 DOM 元素。为下列值之一 + * * - `Emulated` (default): Emulate native scoping of styles. + * + * `Emulated`(默认):模拟样式的原生作用域。 + * * - `Native`: Use the native encapsulation mechanism of the renderer. + * + * `Native` :使用渲染器的原生封装机制。 + * * - `ShadowDom`: Use modern [Shadow * DOM](https://w3c.github.io/webcomponents/spec/shadow/) and * create a ShadowRoot for component's host element. + * + * `ShadowDom` :使用现代的 [Shadow DOM](https://w3c.github.io/webcomponents/spec/shadow/) 并为组件的宿主元素创建 ShadowRoot。 + * * - `None`: Do not provide any template or style encapsulation. + * + * `None` :不提供任何模板或样式封装。 + * */ encapsulation: ViewEncapsulation; /** * Defines CSS styles to be stored on a renderer instance. + * + * 定义要存储在渲染器实例上的 CSS 样式。 + * */ styles: (string|any[])[]; /** * Defines arbitrary developer-defined data to be stored on a renderer instance. * This is useful for renderers that delegate to other renderers. + * + * 定义要存储在渲染器实例上的任意由开发人员定义的数据。这对于要委托其他渲染器实现的渲染器很有用。 + * */ data: {[kind: string]: any}; } @@ -45,6 +72,9 @@ export interface RendererType2 { /** * Flags for renderer-specific style modifiers. + * + * 渲染器特有样式修饰符的标志。 + * * @publicApi */ export enum RendererStyleFlags2 { @@ -53,10 +83,16 @@ export enum RendererStyleFlags2 { // the tests. The work around is to have hard coded value in `node_manipulation.ts` for now. /** * Marks a style as important. + * + * 将样式标记为重要。 + * */ Important = 1 << 0, /** * Marks a style as using dash case naming (this-is-dash-case). + * + * 将样式标记为使用中线命名法(this-is-dash-case)。 + * */ DashCase = 1 << 1 } diff --git a/packages/core/src/render3/di.ts b/packages/core/src/render3/di.ts index 0decb16f94..277dcff6aa 100644 --- a/packages/core/src/render3/di.ts +++ b/packages/core/src/render3/di.ts @@ -274,13 +274,23 @@ export function diPublicInInjector( /** * Inject static attribute value into directive constructor. * + * 将静态属性值注入到指令构造函数中。 + * * This method is used with `factory` functions which are generated as part of * `defineDirective` or `defineComponent`. The method retrieves the static value * of an attribute. (Dynamic attributes are not supported since they are not resolved * at the time of injection and can change over time.) * + * 本方法与 `factory` 函数一起使用,这些工厂函数是 `defineDirective` 或 `defineComponent` 生成物的一部分。该方法会检索属性的静态值。(不支持动态属性,因为它们在注入时尚无法解析,并且会随着时间变化。) + * * # Example + * + * # 例 + * * Given: + * + * 给定: + * * ``` * @Component(...) * class MyComponent { @@ -288,11 +298,17 @@ export function diPublicInInjector( * } * ``` * When instantiated with + * + * 当使用下列方式实例化时 + * * ``` * * ``` * * Then factory method generated is: + * + * 所生成的工厂方法是: + * * ``` * MyComponent.ɵcmp = defineComponent({ * factory: () => new MyComponent(injectAttribute('title')) diff --git a/packages/core/src/render3/util/change_detection_utils.ts b/packages/core/src/render3/util/change_detection_utils.ts index 3a94e05817..c4b96263b5 100644 --- a/packages/core/src/render3/util/change_detection_utils.ts +++ b/packages/core/src/render3/util/change_detection_utils.ts @@ -13,8 +13,12 @@ import {getRootComponents} from './discovery_utils'; * Marks a component for check (in case of OnPush components) and synchronously * performs change detection on the application this component belongs to. * + * 把一个组件标记为需要检查(OnPush 组件中),并且在本组件所属的应用中同步执行执行变更检测。 + * * @param component Component to {@link ChangeDetectorRef#markForCheck mark for check}. * + * 要 {@link ChangeDetectorRef#markForCheck 标记为需要检查}的组件。 + * * @publicApi * @globalApi ng */ diff --git a/packages/core/src/render3/util/discovery_utils.ts b/packages/core/src/render3/util/discovery_utils.ts index bf350235fc..9fa8b887f2 100644 --- a/packages/core/src/render3/util/discovery_utils.ts +++ b/packages/core/src/render3/util/discovery_utils.ts @@ -26,8 +26,14 @@ import {getTNode, unwrapRNode} from './view_utils'; /** * Retrieves the component instance associated with a given DOM element. * + * 检索与给定 DOM 元素关联的组件实例。 + * * @usageNotes + * * Given the following DOM structure: + * + * 给定以下 DOM 结构: + * * ```html * *
        @@ -35,16 +41,25 @@ import {getTNode, unwrapRNode} from './view_utils'; *
        *
        * ``` + * * Calling `getComponent` on `` will return the instance of `ChildComponent` * associated with this DOM element. * + * 在 `` 上调用 `getComponent` 将返回与此 DOM 元素关联的 `ChildComponent`。 + * * Calling the function on `` will return the `MyApp` instance. * + * 在 `` 上调用该函数将返回 `MyApp` 实例。 * * @param element DOM element from which the component should be retrieved. + * + * 要从中检索组件的 DOM 元素。 + * * @returns Component instance associated with the element or `null` if there * is no component associated with it. * + * 与元素关联的组件实例;如果没有与之关联的组件,则为 `null` + * * @publicApi * @globalApi ng */ @@ -66,10 +81,17 @@ export function getComponent(element: Element): T|null { * view that the element is part of. Otherwise retrieves the instance of the component whose view * owns the element (in this case, the result is the same as calling `getOwningComponent`). * + * 如果在嵌入式视图中(例如 `*ngIf` 或 `*ngFor`),则检索元素所属的嵌入式视图的上下文。否则,检索其视图中拥有该元素的组件的实例(在这种情况下,其结果与调用 `getOwningComponent` 相同)。 + * * @param element Element for which to get the surrounding component instance. + * + * 要获取外围组件实例的元素。 + * * @returns Instance of the component that is around the element or null if the element isn't * inside any component. * + * 元素外围组件的实例;如果元素不在任何组件内,则为 null。 + * * @publicApi * @globalApi ng */ @@ -82,15 +104,24 @@ export function getContext(element: Element): T|null { /** * Retrieves the component instance whose view contains the DOM element. * + * 检索其视图中包含此 DOM 元素的组件实例。 + * * For example, if `` is used in the template of `` * (i.e. a `ViewChild` of ``), calling `getOwningComponent` on `` * would return ``. * + * 例如,如果 `` 在 `` 的模板中使用(即 `` 的 `ViewChild`),在 `` 上调用 `getOwningComponent` 将返回 ``。 + * * @param elementOrDir DOM element, component or directive instance * for which to retrieve the root components. + * + * 要为其检索根组件的 DOM 元素、组件或指令实例。 + * * @returns Component instance whose view owns the DOM element or null if the element is not * part of a component view. * + * 其视图中拥有 DOM 元素的组件实例;如果该元素不属于组件视图,则为 null。 + * * @publicApi * @globalApi ng */ @@ -111,10 +142,17 @@ export function getOwningComponent(elementOrDir: Element|{}): T|null { * Retrieves all root components associated with a DOM element, directive or component instance. * Root components are those which have been bootstrapped by Angular. * + * 检索与 DOM 元素,指令或组件实例关联的所有根组件。根组件是由 Angular 引导启动的组件。 + * * @param elementOrDir DOM element, component or directive instance * for which to retrieve the root components. + * + * 要检索其根组件的 DOM 元素、组件或指令实例。 + * * @returns Root components associated with the target object. * + * 与目标对象关联的根组件。 + * * @publicApi * @globalApi ng */ @@ -125,10 +163,17 @@ export function getRootComponents(elementOrDir: Element|{}): {}[] { /** * Retrieves an `Injector` associated with an element, component or directive instance. * + * 检索与元素、组件或指令实例关联的 `Injector`。 + * * @param elementOrDir DOM element, component or directive instance for which to * retrieve the injector. + * + * 要为其获取注入器的 DOM 元素、组件或指令实例。 + * * @returns Injector associated with the element, component or directive instance. * + * 与元素、组件或指令实例关联的注入器。 + * * @publicApi * @globalApi ng */ @@ -172,22 +217,38 @@ export function getInjectionTokens(element: Element): any[] { * Retrieves directive instances associated with a given DOM element. Does not include * component instances. * + * 检索与给定 DOM 元素关联的指令实例。不包括组件实例。 + * * @usageNotes + * * Given the following DOM structure: + * + * 给定以下 DOM 结构: + * * ``` * * * * * ``` + * * Calling `getDirectives` on `