docs: 翻译 API 文档

This commit is contained in:
Zhicheng WANG 2021-02-04 19:45:54 +08:00
parent ade723a83d
commit 3b428a1118
194 changed files with 7503 additions and 204 deletions

View File

@ -65,7 +65,7 @@ Most Angular code can be written with just the latest JavaScript, using [types](
有些企业内部的防火墙比较严格,如果无法打开 <https://angular.cn>,你可以在企业内部进行私有化部署。步骤如下:
本文档的预编译版本位于 [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 上做如下改动:

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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.

View File

@ -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`

File diff suppressed because it is too large Load Diff

View File

@ -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'});

View File

@ -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<any>, next: HttpHandler): Observable<HttpEvent<any>>;
}
@ -86,7 +97,7 @@ export class HttpInterceptorHandler implements HttpHandler {
* `HttpInterceptor` objects.
*
*
* multi-provider `HttpInterceptor`
* multi-provider `HttpInterceptor`
*
* @publicApi
*/

View File

@ -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<never>): Observable<HttpEvent<any>> {
// 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<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (req.method === 'JSONP') {

View File

@ -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.
*

View File

@ -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<T> extends HttpResponseBase {
* will contain either a wrapped Error object or the error response returned
* from the server.
*
*
* `Observable` `HttpErrorResponse` 便 HTTP
*
*

View File

@ -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<any>): Observable<HttpEvent<any>> {
// Quick check to give a better error message when a user attempts to use

View File

@ -21,13 +21,20 @@ export const XSRF_HEADER_NAME = new InjectionToken<string>('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;
}

View File

@ -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<any>) => 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<any>) => 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<any>) => 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<any>) => 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<any>) => 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;
}

View File

@ -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({

View File

@ -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<any>): void {
if (this.cancelled) {

View File

@ -13,6 +13,7 @@ type NgClassSupportedTypes = string[]|Set<string>|{[klass: string]: any}|null|un
* @ngModule CommonModule
*
* @usageNotes
*
* ```
* <some-element [ngClass]="'first second'">...</some-element>
*
@ -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) {

View File

@ -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
*
*
*
* ```
* <ng-container *ngComponentOutlet="componentTypeExpression"></ng-container>
* ```
*
* Customized injector/content
*
* /
*
* ```
* <ng-container *ngComponentOutlet="componentTypeExpression;
* injector: injectorExpression;
@ -47,6 +69,9 @@ import {ComponentFactoryResolver, ComponentRef, Directive, Injector, Input, NgMo
* ```
*
* Customized ngModuleFactory
*
* ngModuleFactory
*
* ```
* <ng-container *ngComponentOutlet="componentTypeExpression;
* ngModuleFactory: moduleFactory;">
@ -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:

View File

@ -37,14 +37,20 @@ export class NgForOfContext<T, U extends NgIterable<T> = NgIterable<T>> {
* 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 `<li>` element.
*
* `<li>`
*
* ```
* <li *ngFor="let item of items; index as i; trackBy: trackByFn">...</li>
* ```
@ -54,8 +60,12 @@ export class NgForOfContext<T, U extends NgIterable<T> = NgIterable<T>> {
* The content of the `<ng-template>` element is the `<li>` element that held the
* short-form directive.
*
* 使 `<ng-template>` `ngForOf` `<ng-template>` `<li>`
*
* Here is the expanded version of the short-form example.
*
*
*
* ```
* <ng-template ngFor let-item [ngForOf]="items" let-i="index" [ngForTrackBy]="trackByFn">
* <li>...</li>
@ -66,6 +76,8 @@ export class NgForOfContext<T, U extends NgIterable<T> = NgIterable<T>> {
* 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<T, U extends NgIterable<T> = NgIterable<T>> {
* 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`
*
* ```
* <li *ngFor="let user of users; index as i; first as isFirst">
@ -96,7 +110,7 @@ export class NgForOfContext<T, U extends NgIterable<T> = NgIterable<T>> {
*
* - `$implicit: T`: The value of the individual items in the iterable (`ngForOf`).
*
* `$implicit: T``ngForOf`
* `$implicit: T` `ngForOf`
*
* - `ngForOf: NgIterable<T>`: 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<T, U extends NgIterable<T> = NgIterable<T>> {
* `trackBy`Angular 使
*
* @see [Structural Directives](guide/structural-directives)
*
* [](guide/structural-directives)
*
* @ngModule CommonModule
* @publicApi
*/
@ -188,6 +205,9 @@ export class NgForOf<T, U extends NgIterable<T> = NgIterable<T>> 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<T>|undefined|null) {
@ -197,19 +217,28 @@ export class NgForOf<T, U extends NgIterable<T> = NgIterable<T>> 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<T>) {
@ -240,7 +269,13 @@ export class NgForOf<T, U extends NgIterable<T> = NgIterable<T>> 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<NgForOfContext<T, U>>) {
@ -254,6 +289,9 @@ export class NgForOf<T, U extends NgIterable<T> = NgIterable<T>> implements DoCh
/**
* Applies the changes when needed.
*
*
*
*/
ngDoCheck(): void {
if (this._ngForOfDirty) {
@ -326,8 +364,13 @@ export class NgForOf<T, U extends NgIterable<T> = NgIterable<T>> 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<T, U extends NgIterable<T>>(dir: NgForOf<T, U>, ctx: any):
ctx is NgForOfContext<T, U> {

View File

@ -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 `<ng-template>` element.
*
* 使[](guide/structural-directives#the-asterisk--prefix) `*ngIf="condition"`Angular `<ng-template>`
*
* Simple form with shorthand syntax:
*
*
*
* ```
* <div *ngIf="condition">Content to render when condition is true.</div>
* ```
*
* Simple form with expanded syntax:
*
*
*
* ```
* <ng-template [ngIf]="condition"><div>Content to render when condition is
* true.</div></ng-template>
@ -38,6 +46,8 @@ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef, ɵstri
*
* Form with an "else" block:
*
* else
*
* ```
* <div *ngIf="condition; else elseBlock">Content to render when condition is true.</div>
* <ng-template #elseBlock>Content to render when condition is false.</ng-template>
@ -45,6 +55,8 @@ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef, ɵstri
*
* Shorthand form with "then" and "else" blocks:
*
* then else
*
* ```
* <div *ngIf="condition; then thenBlock else elseBlock"></div>
* <ng-template #thenBlock>Content to render when condition is true.</ng-template>
@ -53,6 +65,8 @@ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef, ɵstri
*
* Form with storing the value locally:
*
*
*
* ```
* <div *ngIf="condition as value; else elseBlock">{{value}}</div>
* <ng-template #elseBlock>Content to render when value is null.</ng-template>
@ -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 `<ng-template>` 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` `<ng-template>` `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 `<ng-template>` element. When you do this, you can
* change which template to use at runtime, as shown in the following example.
*
* then `ngIf` `<ng-template>`
*
* {@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"
*
* ```
* <div class="hero-list" *ngIf="heroes else loading">
* ...
@ -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` `<ng-template>` "then" 宿
*
* However, when Angular expands the shorthand syntax, it creates
* another `<ng-template>` tag, with `ngIf` and `ngIfElse` directives.
* The anchor element containing the template for the "then" clause becomes
* the content of this unlabeled `<ng-template>` tag.
*
* Angular `ngIf` `ngIfElse` `<ng-template>`宿 "then" `<ng-template>`
*
* ```
* <ng-template [ngIf]="heroes" [ngIfElse]="loading">
* <div class="hero-list">
@ -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<T = unknown> {
/**
* The Boolean expression to evaluate as the condition for showing a template.
*
*
*
*/
@Input()
set ngIf(condition: T) {
@ -171,6 +215,9 @@ export class NgIf<T = unknown> {
/**
* A template to show if the condition expression evaluates to true.
*
* true
*
*/
@Input()
set ngIfThen(templateRef: TemplateRef<NgIfContext<T>>|null) {
@ -182,6 +229,9 @@ export class NgIf<T = unknown> {
/**
* A template to show if the condition expression evaluates to false.
*
* false
*
*/
@Input()
set ngIfElse(templateRef: TemplateRef<NgIfContext<T>>|null) {
@ -219,18 +269,28 @@ export class NgIf<T = unknown> {
/**
* 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<T>(dir: NgIf<T>, ctx: any):
ctx is NgIfContext<Exclude<T, false|0|''|null|undefined>> {

View File

@ -17,6 +17,7 @@ import {SwitchView} from './ng_switch';
* @ngModule CommonModule
*
* @usageNotes
*
* ```
* <some-element [ngPlural]="value">
* <ng-template ngPluralCase="=0">there is nothing</ng-template>
@ -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
*
* <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
*
* ```
* <some-element [ngPlural]="value">
* <ng-template ngPluralCase="=0">...</ng-template>
@ -102,6 +120,8 @@ export class NgPlural {
*
* See {@link NgPlural} for more details and example.
*
* {@link NgPlural}
*
* @publicApi
*/
@Directive({selector: '[ngPluralCase]'})

View File

@ -15,18 +15,24 @@ import {Directive, DoCheck, ElementRef, Input, KeyValueChanges, KeyValueDiffer,
*
* Set the font of the containing element to the result of an expression.
*
*
*
* ```
* <some-element [ngStyle]="{'font-style': styleExp}">...</some-element>
* ```
*
* Set the width of the containing element to a pixel value returned by an expression.
*
*
*
* ```
* <some-element [ngStyle]="{'max-width.px': widthExp}">...</some-element>
* ```
*
* Set a collection of style values using an expression that returns key-value pairs.
*
* 使
*
* ```
* <some-element [ngStyle]="objExp">...</some-element>
* ```

View File

@ -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
*
* ```
* <container-element [ngSwitch]="switch_expression">
* ```
@ -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`
*
* ```
* <container-element [ngSwitch]="switch_expression">
* <some-element *ngSwitchCase="match_expression_1">...</some-element>
@ -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:
*
* 使
*
* ```
* <container-element [ngSwitch]="switch_expression">
* <!-- the same view can be shown in more than one case -->
@ -79,6 +99,9 @@ export class SwitchView {
* ```
*
* The following example shows how cases can be nested:
*
*
*
* ```
* <container-element [ngSwitch]="switch_expression">
* <some-element *ngSwitchCase="match_expression_1">...</some-element>
@ -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`
*
* ```
* <container-element [ngSwitch]="switch_expression">
* <some-element *ngSwitchCase="match_expression_1">...</some-element>
@ -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`

View File

@ -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<any>|null = null;

View File

@ -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<Document>('DocumentToken');

View File

@ -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 {

View File

@ -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 使 registerLocaleDatadataanyextraData ?: any
*
* @publicApi
*/
export function registerLocaleData(data: any, localeId?: string|any, extraData?: any): void {

View File

@ -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%
*
* 10023.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
*
* 100023.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
*
* <b>Important:</b> 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-timeto-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` morningnoonafternoonevening 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<T>(data: T[], index: number): T {
@ -615,6 +1009,8 @@ function getLastDefinedValue<T>(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 {

View File

@ -48,6 +48,8 @@ export function getPluralCategory(
/**
* Returns the plural case based on the locale
*
*
*
* @publicApi
*/
@Injectable()

View File

@ -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

View File

@ -61,6 +61,8 @@ export interface PopStateEvent {
*
* ### Example
*
* ###
*
* <code-example path='common/location/ts/path_location_component.ts'
* region='LocationComponent'></code-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

View File

@ -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
* <code class="no-auto-link">http://example.com#/foo</code>,
* and `PathLocationStrategy` produces
* <code class="no-auto-link">http://example.com/foo</code> as an equivalent URL.
*
* `HashLocationStrategy` <code class="no-auto-link">http://example.com#/foo</code> 这样的 URL而 `PathLocationStrategy` 会处理像 <code class="no-auto-link">http://example.com/foo</code> 这样的等价 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 hrefbase 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<string>('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 `<base href>` element to the document.
*
* 使 `PathLocationStrategy` {@link APP_BASE_HREF} `<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 `<base href>` and/or `APP_BASE_HREF` should end with a `/`.
*
* `APP_BASE_HREF` `'/my/app/'` `location.go('/foo')` URL `example.com/my/app/foo` URI `<base href>` / `APP_BASE_HREF` `/`
*
* Similarly, if you add `<base href='/my/app/'/>` to the document and call
* `location.go('/foo')`, the browser's URL will become
* `example.com/my/app/foo`.
*
* `<base href='/my/app/'/>` `location.go('/foo')` URL `example.com/my/app/foo`
*
* Note that when using `PathLocationStrategy`, neither the query nor
* the fragment in the `<base href>` 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) 所述,查询和 `<base href>` 的片段部分都不会保留。
*
* @usageNotes
*
* ### Example
*
* ###
*
* {@example common/location/ts/path_location_component.ts region='LocationComponent'}
*
* @publicApi

View File

@ -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 pushStatepopState 使 `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<Promise<any>>('Location Initialized');
@ -76,6 +86,8 @@ export const LOCATION_INITIALIZED = new InjectionToken<Promise<any>>('Location I
* @description
* A serializable version of the event from `onPopState` or `onHashChange`
*
* `onPopState` `onHashChange`
*
* @publicApi
*/
export interface LocationChangeEvent {

View File

@ -73,6 +73,7 @@ const unicodeWordMatch =
* @see `UpperCasePipe`
*
* @usageNotes
*
* The following example shows the result of transforming various strings into title case.
*
*

View File

@ -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';
*
* `*`
*
* | <t>Field type</t><t></t> | <t>Format</t><t></t> | <t>Description</t><t></t> | <t>Example Value</t><t></t> |
* |--------------------|-------------|---------------------------------------------------------------|------------------------------------------------------------|
* | <t>Era</t><t></t> | G, GG & GGG | <t>Abbreviated</t><t></t>| AD |
* | | GGGG | <t>Wide</t><t></t>| Anno Domini |
* | | GGGGG | <t>Narrow</t><t></t>| A |
* | <t>Year</t><t></t> | y | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 2, 20, 201, 2017, 20173 |
* | | yy | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 02, 20, 01, 17, 73 |
* | | yyy | <t>Numeric</t><t></t>: 3 <t>digits + zero padded</t><t> + 0 </t> | 002, 020, 201, 2017, 20173 |
* | | yyyy | <t>Numeric</t><t></t>: 4 <t>digits or more + zero padded</t><t> + 0 </t> | 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 |
* | <t>Month</t><t></t> | M | <t>Numeric</t><t></t>: <t>1 digit</t><t>1 </t> | 9, 12 |
* | | MM | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 09, 12 |
* | | MMM | <t>Abbreviated</t><t></t>| Sep |
* | | MMMM | <t>Wide</t><t></t>| September |
* | | MMMMM | <t>Narrow</t><t></t>| S |
* | <t>Month standalone</t><t></t> | L | <t>Numeric</t><t></t>: <t>1 digit</t><t>1 </t> | 9, 12 |
* | | LL | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 09, 12 |
* | | LLL | <t>Abbreviated</t><t></t>| Sep |
* | | LLLL | <t>Wide</t><t></t>| September |
* | | LLLLL | <t>Narrow</t><t></t>| S |
* | <t>Week of year</t><t></t> | w | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 1... 53 |
* | | ww | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 01... 53 |
* | <t>Week of month</t><t></t> | W | <t>Numeric</t><t></t>: <t>1 digit</t><t>1 </t> | 1... 5 |
* | <t>Day of month</t><t></t> | d | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 1 |
* | | dd | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 01 |
* | <t>Week day</t><t></t> | E, EE & EEE | <t>Abbreviated</t><t></t>| Tue |
* | | EEEE | <t>Wide</t><t></t>| Tuesday |
* | | EEEEE | <t>Narrow</t><t></t>| T |
* | | EEEEEE | <t>Short</t><t></t> | Tu |
* | <t>Period</t><t></t> | a, aa & aaa | <t>Abbreviated</t><t></t>| am/pm or AM/PM |
* | | aaaa | <t>Wide</t><t></t><t>(fallback to `a` when missing)</t><t>( `a`)</t>| ante meridiem/post meridiem |
* | | aaaaa | <t>Narrow</t><t></t>| a/p |
* | <t>Period*</t><t></t> | B, BB & BBB | <t>Abbreviated</t><t></t>| mid. |
* | | BBBB | <t>Wide</t><t></t>| am, pm, midnight, noon, morning, afternoon, evening, night |
* | | BBBBB | <t>Narrow</t><t></t>| md |
* | <t>Period standalone*</t><t></t> | b, bb & bbb | <t>Abbreviated</t><t></t>| mid. |
* | | bbbb | <t>Wide</t><t></t>| am, pm, midnight, noon, morning, afternoon, evening, night |
* | | bbbbb | <t>Narrow</t><t></t>| md |
* | <t>Hour 1-12</t><t>(1-12)</t> | h | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 1, 12 |
* | | hh | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 01, 12 |
* | <t>Hour 0-23</t><t>(0-23)</t> | H | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 0, 23 |
* | | HH | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 00, 23 |
* | <t>Minute</t><t></t> | m | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 8, 59 |
* | | mm | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 08, 59 |
* | <t>Second</t><t></t> | s | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 0... 59 |
* | | ss | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 00... 59 |
* | <t>Fractional seconds</t><t></t> | S | <t>Numeric</t><t></t>: <t>1 digit</t><t>1 </t> | 0... 9 |
* | | SS | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 00... 99 |
* | | SSS | <t>Numeric</t><t></t>: 3 <t>digits + zero padded</t><t> + 0 </t> (= <t>milliseconds</t><t></t>) | 000... 999 |
* | <t>Zone</t><t></t> | z, zz & zzz | <t>Short specific non location format (fallback to O)</t><t>0</t> | GMT-8 |
* | | zzzz | <t>Long specific non location format (fallback to OOOO)</t><t>0000</t> | GMT-08:00 |
* | | Z, ZZ & ZZZ | ISO8601 <t>basic format</t><t></t> | -0800 |
* | | ZZZZ | <t>Long localized GMT format</t><t> GMT </t> | GMT-8:00 |
* | | ZZZZZ | ISO8601 <t>extended format + Z indicator for offset 0</t><t> + 0 Z </t> (= XXXXX) | -08:00 |
* | | O, OO & OOO | <t>Short localized GMT format</t><t> GMT </t> | GMT-8 |
* | | OOOO | <t>Long localized GMT format</t><t> GMT </t> | GMT-08:00 |
* | <t>Field type</t><t></t> | <t>Format</t><t></t> | <t>Description</t><t></t> | <t>Example Value</t><t></t> |
* | -------------------------------- | ------------------------ | ----------------------------- | --------------------------------- |
* | <t>Era</t><t></t> | G, GG & GGG | <t>Abbreviated</t><t></t> | AD |
* | | GGGG | <t>Wide</t><t></t> | Anno Domini |
* | | GGGGG | <t>Narrow</t><t></t> | A |
* | <t>Year</t><t></t> | y | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 2, 20, 201, 2017, 20173 |
* | | yy | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 02, 20, 01, 17, 73 |
* | | yyy | <t>Numeric</t><t></t>: 3 <t>digits + zero padded</t><t> + 0 </t> | 002, 020, 201, 2017, 20173 |
* | | yyyy | <t>Numeric</t><t></t>: 4 <t>digits or more + zero padded</t><t> + 0 </t> | 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 |
* | <t>Month</t><t></t> | M | <t>Numeric</t><t></t>: <t>1 digit</t><t>1 </t> | 9, 12 |
* | | MM | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 09, 12 |
* | | MMM | <t>Abbreviated</t><t></t> | Sep |
* | | MMMM | <t>Wide</t><t></t> | September |
* | | MMMMM | <t>Narrow</t><t></t> | S |
* | <t>Month standalone</t><t></t> | L | <t>Numeric</t><t></t>: <t>1 digit</t><t>1 </t> | 9, 12 |
* | | LL | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 09, 12 |
* | | LLL | <t>Abbreviated</t><t></t> | Sep |
* | | LLLL | <t>Wide</t><t></t> | September |
* | | LLLLL | <t>Narrow</t><t></t> | S |
* | <t>Week of year</t><t></t> | w | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 1... 53 |
* | | ww | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 01... 53 |
* | <t>Week of month</t><t></t> | W | <t>Numeric</t><t></t>: <t>1 digit</t><t>1 </t> | 1... 5 |
* | <t>Day of month</t><t></t> | d | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 1 |
* | | dd | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 01 |
* | <t>Week day</t><t></t> | E, EE & EEE | <t>Abbreviated</t><t></t> | Tue |
* | | EEEE | <t>Wide</t><t></t> | Tuesday |
* | | EEEEE | <t>Narrow</t><t></t> | T |
* | | EEEEEE | <t>Short</t><t></t> | Tu |
* | <t>Period</t><t></t> | a, aa & aaa | <t>Abbreviated</t><t></t> | am/pm or AM/PM |
* | | aaaa | <t>Wide</t><t></t><t>(fallback to `a` when missing)</t><t>( `a`)</t> | ante meridiem/post meridiem |
* | | aaaaa | <t>Narrow</t><t></t> | a/p |
* | <t>Period\*</t><t></t> | B, BB & BBB | <t>Abbreviated</t><t></t> | mid. |
* | | BBBB | <t>Wide</t><t></t> | am, pm, midnight, noon, morning, afternoon, evening, night |
* | | BBBBB | <t>Narrow</t><t></t> | md |
* | <t>Period standalone\*</t><t></t> | b, bb & bbb | <t>Abbreviated</t><t></t> | mid. |
* | | bbbb | <t>Wide</t><t></t> | am, pm, midnight, noon, morning, afternoon, evening, night |
* | | bbbbb | <t>Narrow</t><t></t> | md |
* | <t>Hour 1-12</t><t>(1-12)</t> | h | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 1, 12 |
* | | hh | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 01, 12 |
* | <t>Hour 0-23</t><t>(0-23)</t> | H | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 0, 23 |
* | | HH | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 00, 23 |
* | <t>Minute</t><t></t> | m | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 8, 59 |
* | | mm | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 08, 59 |
* | <t>Second</t><t></t> | s | <t>Numeric</t><t></t>: <t>minimum digits</t><t></t> | 0... 59 |
* | | ss | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 00... 59 |
* | <t>Fractional seconds</t><t></t> | S | <t>Numeric</t><t></t>: <t>1 digit</t><t>1 </t> | 0... 9 |
* | | SS | <t>Numeric</t><t></t>: 2 <t>digits + zero padded</t><t> + 0 </t> | 00... 99 |
* | | SSS | <t>Numeric</t><t></t>: 3 <t>digits + zero padded</t><t> + 0 </t> (= <t>milliseconds</t><t></t>) | 000... 999 |
* | <t>Zone</t><t></t> | z, zz & zzz | <t>Short specific non location format (fallback to O)</t><t> 0</t> | GMT-8 |
* | | zzzz | <t>Long specific non location format (fallback to OOOO)</t><t> 0000</t> | GMT-08:00 |
* | | Z, ZZ & ZZZ | ISO8601 <t>basic format</t><t></t> | -0800 |
* | | ZZZZ | <t>Long localized GMT format</t><t> GMT </t> | GMT-8:00 |
* | | ZZZZZ | ISO8601 <t>extended format + Z indicator for offset 0</t><t> + 0 Z </t> (= XXXXX) | -08:00 |
* | | O, OO & OOO | <t>Short localized GMT format</t><t> GMT </t> | GMT-8 |
* | | OOOO | <t>Long localized GMT format</t><t> GMT </t> | 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.

View File

@ -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 <http://userguide.icu-project.org/formatparse/messages>
*
* @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 {

View File

@ -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 '';

View File

@ -16,6 +16,8 @@ function makeKeyValuePair<K, V>(key: K, value: V): KeyValue<K, V> {
* A key value pair.
* Usually used to represent the key value pairs from a Map or Object.
*
* Map Object
*
* @publicApi
*/
export interface KeyValue<K, V> {
@ -29,16 +31,25 @@ export interface KeyValue<K, V> {
*
* 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

View File

@ -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`.

View File

@ -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 {

View File

@ -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;
}

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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` URLwindow.location AngularJS URLwindow.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.<string>|Object.<Array.<string>>} 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<string>|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 &lt;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.');

View File

@ -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<string>('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]})

View File

@ -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 {

View File

@ -28,6 +28,8 @@ export interface LocationUpgradeTestingConfig {
*
* Is used in DI to configure the router.
*
* DI
*
* @publicApi
*/
export const LOC_UPGRADE_TEST_CONFIG =

View File

@ -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<Array<() => void>>('Applicatio
/**
* A class that reflects the state of running {@link APP_INITIALIZER} functions.
*
* {@link APP_INITIALIZER}
*
* @publicApi
*/
@Injectable()

View File

@ -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})

View File

@ -130,6 +130,8 @@ export const ALLOW_MULTIPLE_PLATFORMS = new InjectionToken<boolean>('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<T extends Object>(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<any>[] = [];
/**
* Get a list of components registered to this application.
*
*
*
*/
public readonly components: ComponentRef<any>[] = [];
/**
* 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<boolean>;
@ -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<C>(componentOrFactory: ComponentFactory<C>|Type<C>, 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;

View File

@ -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 <!-- TODO: provider --> to configure
* the root {@link Injector} that uses this token.
*
* Angular ID 使 DI {@link Injector} 使
*
* @publicApi
*/
export const APP_ID = new InjectionToken<string>('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<Array<() => void>>('Platform Initializer');
/**
* A token that indicates an opaque platform ID.
*
* ID
*
* @publicApi
*/
export const PLATFORM_ID = new InjectionToken<Object>('Platform ID');
@ -57,8 +70,12 @@ export const PLATFORM_ID = new InjectionToken<Object>('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<string>('Application Packages Root URL');

View File

@ -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

View File

@ -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!;
}
}

View File

@ -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,
}

View File

@ -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<V> implements IterableDiffer<V>, IterableChanges<V> {
@ -231,6 +234,8 @@ export class DefaultIterableDiffer<V> implements IterableDiffer<V>, 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<V> implements IterableDiffer<V>, 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_<V>|null, item: V, itemTrackBy: any, index: number):
@ -310,20 +325,51 @@ export class DefaultIterableDiffer<V> implements IterableDiffer<V>, 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. &lt;-- this is wrong!
*
* `a` `1` &lt;--
*
* 1. reinsert `a` at index 2. &lt;-- this is wrong!
*
* `a` `2` &lt;--
*
* 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<V> implements IterableDiffer<V>, 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_<V>, item: V, itemTrackBy: any, index: number):
@ -350,7 +398,11 @@ export class DefaultIterableDiffer<V> implements IterableDiffer<V>, 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
*/

View File

@ -16,6 +16,8 @@ import {DefaultIterableDifferFactory} from '../differs/default_iterable_differ';
/**
* A type describing supported iterable types.
*
*
*
* @publicApi
*/
export type NgIterable<T> = Array<T>|Iterable<T>;
@ -24,15 +26,25 @@ export type NgIterable<T> = Array<T>|Iterable<T>;
* 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<V> {
/**
* 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<V>|undefined|null): IterableChanges<V>|null;
}
@ -41,12 +53,17 @@ export interface IterableDiffer<V> {
* An object describing the changes in the `Iterable` collection since last time
* `IterableDiffer#diff()` was invoked.
*
* `IterableDiffer#diff()` `Iterable`
*
* @publicApi
*/
export interface IterableChanges<V> {
/**
* Iterate over all changes. `IterableChangeRecord` will contain information about changes
* to each item.
*
* `IterableChangeRecord`
*
*/
forEachItem(fn: (record: IterableChangeRecord<V>) => void): void;
@ -54,17 +71,30 @@ export interface IterableChanges<V> {
* 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<V> {
/**
* Iterate over changes in the order of original `Iterable` showing where the original items
* have moved.
*
* `Iterable`
*
*/
forEachPreviousItem(fn: (record: IterableChangeRecord<V>) => void): void;
/** Iterate over all added items. */
/**
* Iterate over all added items.
*
*
*
*/
forEachAddedItem(fn: (record: IterableChangeRecord<V>) => void): void;
/** Iterate over all moved items. */
/**
* Iterate over all moved items.
*
*
*
*/
forEachMovedItem(fn: (record: IterableChangeRecord<V>) => void): void;
/** Iterate over all removed items. */
/**
* Iterate over all removed items.
*
*
*
*/
forEachRemovedItem(fn: (record: IterableChangeRecord<V>) => void): void;
/**
* Iterate over all items which had their identity (as computed by the `TrackByFunction`)
* changed.
*
* `TrackByFunction`
*
*/
forEachIdentityChange(fn: (record: IterableChangeRecord<V>) => void): void;
}
@ -96,19 +147,41 @@ export interface IterableChanges<V> {
/**
* Record representing the item change information.
*
*
*
* @publicApi
*/
export interface IterableChangeRecord<V> {
/** 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<V> {
* 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<T> {
@ -127,6 +202,8 @@ export interface TrackByFunction<T> {
/**
* 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.
*
* NgForNgClass 使
*
* @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: [

View File

@ -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<K, V> {
/**
* 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<K, V>): KeyValueChanges<K, V>|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<string, V>|null;
// TODO(TS2.1): diff<KP extends string>(this: KeyValueDiffer<KP, V>, object: Record<KP, V>):
@ -41,33 +59,50 @@ export interface KeyValueDiffer<K, V> {
* 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<K, V> {
/**
* Iterate over all changes. `KeyValueChangeRecord` will contain information about changes
* to each item.
*
* `KeyValueChangeRecord`
*
*/
forEachItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
/**
* Iterate over changes in the order of original Map showing where the original items
* have moved.
*
*
*
*/
forEachPreviousItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
/**
* Iterate over all keys for which values have changed.
*
*
*
*/
forEachChangedItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
/**
* Iterate over all added items.
*
*
*
*/
forEachAddedItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
/**
* Iterate over all removed items.
*
*
*
*/
forEachRemovedItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
}
@ -75,21 +110,32 @@ export interface KeyValueChanges<K, V> {
/**
* Record representing the item change information.
*
*
*
* @publicApi
*/
export interface KeyValueChangeRecord<K, V> {
/**
* 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<K, V> {
/**
* 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<K, V>(): KeyValueDiffer<K, V>;
}
@ -114,6 +168,8 @@ export interface KeyValueDifferFactory {
/**
* A repository of different Map diffing strategies used by NgClass, NgStyle, and others.
*
* NgClassNgStyle 使
*
* @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: [

View File

@ -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<T> {

View File

@ -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<any> {
/**
* 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`

View File

@ -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<any>|'root'|'platform'|'any'|null;
}

View File

@ -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<MyInterface>('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

View File

@ -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<T>(
token: Type<T>|AbstractType<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
/**
* @deprecated from v4.0.0 use Type<T>, AbstractType<T> or InjectionToken<T>
*
* v4.0.0 Type<T>AbstractType<T> InjectionToken<T>
*
* @suppress {duplicate}
*/
abstract get(token: any, notFoundValue?: any): any;
/**
* @deprecated from v5 use the new signature Injector.create(options)
*
* v5 使 Injector.createoptions
*
*/
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;

View File

@ -63,13 +63,22 @@ export function injectInjectorOnly<T>(
/**
* 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

View File

@ -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<Injector>(

View File

@ -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<T> {
/**
* 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<any>|'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<any>) => 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<T> {
/**
* 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<T> extends Type<T> {
/**
* Opaque type whose structure is highly version dependent. Do not rely on any properties.
*
*
*
*/
ɵprov: never;
}
@ -97,13 +136,20 @@ export interface InjectableType<T> extends Type<T> {
/**
* A type which has an `InjectorDef` static field.
*
* `InjectorDef`
*
* `InjectorDefTypes` can be used to configure a `StaticInjector`.
*
* `StaticInjector` `InjectorDefTypes`
*
* @publicApi
*/
export interface InjectorType<T> extends Type<T> {
/**
* Opaque type whose structure is highly version dependent. Do not rely on any properties.
*
*
*
*/
ɵinj: never;
}
@ -127,16 +173,28 @@ export interface InjectorTypeWithProviders<T> {
* 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<T>(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;

View File

@ -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,
}

View File

@ -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<any>;
/**
* 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<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;
}
@ -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<any> {}
* 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<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='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

View File

@ -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()`
*
* <code-example path="core/di/ts/metadata_spec.ts" region="InjectWithoutDecorator">
* </code-example>
*
* @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:
*
*
*
* <code-example path="core/di/ts/metadata_spec.ts" region="Optional">
* </code-example>
*
* @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.
*
*
*
* <code-example path="core/di/ts/metadata_spec.ts" region="Self">
* </code-example>
*
@ -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.
*
*
*
* <code-example path="core/di/ts/metadata_spec.ts" region="SkipSelf">
* </code-example>
*
* @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` 使
*
* <code-example path="core/di/ts/metadata_spec.ts" region="Host">
* </code-example>
*
* 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
*/

View File

@ -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 `<input>` element and want to know its `type`.
*
* `<input>` `type`
*
* ```html
* <input type="text">
* ```
*
* 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
*/

View File

@ -75,6 +75,8 @@ interface Record<T> {
/**
* Create a new `Injector` which is configured using a `defType` of `InjectorType<any>`s.
*
* `Injector` 使 `InjectorType<any>` `defType`
*
* @publicApi
*/
export function createInjector(

View File

@ -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<any>|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

View File

@ -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.
*
*
*
* <!-- TODO: Add a link to the section of the user guide talking about hierarchical injection.
* -->
*/
@ -161,15 +198,22 @@ export abstract class ReflectiveInjector implements Injector {
/**
* Resolves an array of providers and creates a child injector from those providers.
*
*
*
* <!-- TODO: Add a link to the section of the user guide talking about hierarchical injection.
* -->
*
* 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.
*
*
*
* <!-- TODO: Add a link to the section of the user guide talking about hierarchical injection.
* -->
*
* 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 {

View File

@ -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;

View File

@ -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<any>`.
*
* Key `Type<any>`
*
*/
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 {

View File

@ -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) {

View File

@ -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<T> extends Subject<T> {
@ -71,6 +80,8 @@ export interface EventEmitter<T> extends Subject<T> {
* 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<T> extends Subject<T> {
/**
* 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;
}

View File

@ -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 DatePipeI18nPluralPipeCurrencyPipeDecimalPipe 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<string>('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)
*
* <div class="alert is-helpful">
*
* **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<string>('LocaleId');
* </div>
*
* @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<string>('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<string>('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<string>('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';

View File

@ -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.
*

View File

@ -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

View File

@ -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<any> {
* Represents an abstract class `T`, if applied to a concrete class it would stop being
* instantiable.
*
* `T`
*
* @publicApi
*/
export interface AbstractType<T> extends Function {

View File

@ -25,6 +25,8 @@ import {NgModuleFactory} from './ng_module_factory';
/**
* Combination of NgModuleFactory and ComponentFactorys.
*
* NgModuleFactory ComponentFactory
*
* @publicApi
*/
export class ModuleWithComponentFactories<T> {
@ -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: <T>(moduleType: Type<T>) => NgModuleFactory<T> = Compiler_compileModuleSync;
/**
* Compiles the given NgModule and all of its components
*
* NgModule
*
*/
compileModuleAsync:
<T>(moduleType: Type<T>) => Promise<NgModuleFactory<T>> = Compiler_compileModuleAsync;
/**
* Same as {@link #compileModuleSync} but also creates ComponentFactories for all components.
*
* {@link #compileModuleSync} ComponentFactory
*
*/
compileModuleAndAllComponentsSync: <T>(moduleType: Type<T>) => ModuleWithComponentFactories<T> =
Compiler_compileModuleAndAllComponentsSync;
/**
* Same as {@link #compileModuleAsync} but also creates ComponentFactories for all components.
*
* {@link #compileModuleAsync} ComponentFactory
*
*/
compileModuleAndAllComponentsAsync: <T>(moduleType: Type<T>) =>
Promise<ModuleWithComponentFactories<T>> = Compiler_compileModuleAndAllComponentsAsync;
/**
* Clears all caches.
*
*
*
*/
clearCache(): void {}
/**
* Clears the cache for the given component/ngModule.
*
* /ngModule
*
*/
clearCacheFor(type: Type<any>) {}
/**
* Returns the id for a given NgModule, if one is defined and known to the compiler.
*
* NgModule ID
*
*/
getModuleId(moduleType: Type<any>): 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[]>('compilerOptions');
@ -161,6 +192,8 @@ export const COMPILER_OPTIONS = new InjectionToken<CompilerOptions[]>('compilerO
/**
* A factory for creating a Compiler
*
*
*
* @publicApi
*/
export abstract class CompilerFactory {

View File

@ -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<C> {
/**
* 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<any>;
/**
* 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<C> {
* 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<C> {
/**
* The component's HTML selector.
*
* HTML
*
*/
abstract get selector(): string;
/**
* The type of component the factory will create.
*
*
*
*/
abstract get componentType(): Type<any>;
/**
* Selector for all <ng-content> elements in the component.
*
* <ng-content>
*
*/
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,

View File

@ -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<T>(component: Type<T>): ComponentFactory<T>;
}

View File

@ -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<T> {
/**
* 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;
}

View File

@ -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<NgModuleFactory<any>>;
@ -40,6 +45,9 @@ export function getModuleFactory__POST_R3__(id: string): NgModuleFactory<any> {
* 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<any> = getModuleFactory__PRE_R3__;

View File

@ -25,6 +25,9 @@ const modules = new Map<string, NgModuleFactory<any>|NgModuleType>();
/**
* Registers a loaded module. Should only be called from generated NgModuleFactory code.
*
* NgModuleFactory
*
* @publicApi
*/
export function registerModuleFactory(id: string, factory: NgModuleFactory<any>) {

View File

@ -42,6 +42,7 @@ function symbolIterator<T>(this: QueryList<T>): Iterator<T> {
* `Observable`
*
* @usageNotes
*
* ### Example
*
* ###
@ -78,6 +79,9 @@ export class QueryList<T> implements Iterable<T> {
/**
* Returns the QueryList entry at `index`.
*
* `index` QueryList
*
*/
get(index: number): T|undefined {
return this._results[index];
@ -145,6 +149,9 @@ export class QueryList<T> implements Iterable<T> {
/**
* Returns a copy of the internal results list as an Array.
*
*
*
*/
toArray(): T[] {
return this._results.slice();
@ -159,7 +166,11 @@ export class QueryList<T> implements Iterable<T> {
* 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<T|any[]>): void {
this._results = flatten(resultsTree);
@ -171,6 +182,9 @@ export class QueryList<T> implements Iterable<T> {
/**
* Triggers a change event by emitting on the `changes` {@link EventEmitter}.
*
* `changes` {@link EventEmitter}
*
*/
notifyOnChanges(): void {
(this.changes as EventEmitter<any>).emit(this);

View File

@ -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 {

View File

@ -88,7 +88,12 @@ export abstract class ViewContainerRef {
*/
abstract get injector(): Injector;
/** @deprecated No replacement */
/**
* @deprecated No replacement
*
*
*
*/
abstract get parentInjector(): Injector;
/**

View File

@ -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}}
* <ul>
@ -62,6 +85,8 @@ export abstract class ViewRef extends ChangeDetectorRef {
*
* This is the outer `TemplateRef`:
*
* `TemplateRef`
*
* ```
* Count: {{items.length}}
* <ul>
@ -71,12 +96,16 @@ export abstract class ViewRef extends ChangeDetectorRef {
*
* This is the inner `TemplateRef`:
*
* `TemplateRef`
*
* ```
* <li>{{item}}</li>
* ```
*
* The outer and inner `TemplateRef` instances are assembled into views as follows:
*
* `TemplateRef`
*
* ```
* <!-- ViewRef: outer-0 -->
* Count: 2
@ -92,11 +121,17 @@ export abstract class ViewRef extends ChangeDetectorRef {
export abstract class EmbeddedViewRef<C> 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[];
}

View File

@ -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<any>('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 `<input>` element and want to know its `type`.
*
* `<input>` `type`
*
* ```html
* <input type="text">
* ```
*
* 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 `<ng-template></ng-template>` with `@ViewChild(TemplateRef)
* template;`)

View File

@ -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<Type<any>|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.
*
* 宿

View File

@ -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) {

View File

@ -31,6 +31,8 @@ export type ɵɵNgModuleDefWithMeta<T, Declarations, Imports, Exports> = NgModul
*
* @see [Deprecations](guide/deprecations#modulewithproviders-type-without-a-generic)
*
* [](guide/deprecations#modulewithproviders-type-without-a-generic)
*
* @publicApi
*/
export interface ModuleWithProviders<T> {
@ -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<Type<any>|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;
}

View File

@ -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 = {

View File

@ -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
}

View File

@ -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);

View File

@ -22,27 +22,53 @@ export const Renderer2Interceptor = new InjectionToken<Renderer2[]>('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<any>;
}
@ -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;
/**

View File

@ -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
}

Some files were not shown because too many files have changed in this diff Show More