@angular/common
Version:
Angular - commonly needed directives and services
53 lines (52 loc) • 1.92 kB
TypeScript
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { ChangeDetectorRef, OnDestroy, PipeTransform } from '@angular/core';
import { Observable } from 'rxjs/Observable';
/**
* @ngModule CommonModule
* @whatItDoes Unwraps a value from an asynchronous primitive.
* @howToUse `observable_or_promise_expression | async`
* @description
* The `async` pipe subscribes to an `Observable` or `Promise` and returns the latest value it has
* emitted. When a new value is emitted, the `async` pipe marks the component to be checked for
* changes. When the component gets destroyed, the `async` pipe unsubscribes automatically to avoid
* potential memory leaks.
*
*
* ## Examples
*
* This example binds a `Promise` to the view. Clicking the `Resolve` button resolves the
* promise.
*
* {@example common/pipes/ts/async_pipe.ts region='AsyncPipePromise'}
*
* It's also possible to use `async` with Observables. The example below binds the `time` Observable
* to the view. The Observable continuously updates the view with the current time.
*
* {@example common/pipes/ts/async_pipe.ts region='AsyncPipeObservable'}
*
* @stable
*/
export declare class AsyncPipe implements OnDestroy, PipeTransform {
private _ref;
private _latestValue;
private _latestReturnedValue;
private _subscription;
private _obj;
private _strategy;
constructor(_ref: ChangeDetectorRef);
ngOnDestroy(): void;
transform<T>(obj: null): null;
transform<T>(obj: undefined): undefined;
transform<T>(obj: Observable<T> | null | undefined): T | null;
transform<T>(obj: Promise<T> | null | undefined): T | null;
private _subscribe(obj);
private _selectStrategy(obj);
private _dispose();
private _updateLatestValue(async, value);
}