From 00376e8ef123024e986b25978368a9999c3e52fc Mon Sep 17 00:00:00 2001 From: Tom Schoener Date: Sat, 28 May 2016 12:38:02 +0200 Subject: [PATCH] docs(async-pipe): include observable example Adds the missing example, usage case and a bit more description to the async-pipe. --- modules/@angular/common/src/pipes/async_pipe.ts | 17 ++++++++++++----- .../pipes/ts/async_pipe/async_pipe_example.ts | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/@angular/common/src/pipes/async_pipe.ts b/modules/@angular/common/src/pipes/async_pipe.ts index 9b6bf6561b9e5..4ae366e6befdf 100644 --- a/modules/@angular/common/src/pipes/async_pipe.ts +++ b/modules/@angular/common/src/pipes/async_pipe.ts @@ -36,22 +36,29 @@ var _observableStrategy = new ObservableStrategy(); var __unused: Promise; // avoid unused import when Promise union types are erased /** - * The `async` pipe subscribes to an Observable or Promise and returns the latest value it has + * 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. * - * ### Example + * ## Usage + * + * object | async + * + * where `object` is of type `Observable` or of type `Promise`. + * + * ## Examples * * This example binds a `Promise` to the view. Clicking the `Resolve` button resolves the * promise. * - * {@example core/pipes/ts/async_pipe/async_pipe_example.ts region='AsyncPipe'} + * {@example core/pipes/ts/async_pipe/async_pipe_example.ts region='AsyncPipePromise'} * * It's also possible to use `async` with Observables. The example below binds the `time` Observable * to the view. Every 500ms, the `time` Observable updates the view with the current time. * - * ```typescript - * ``` + * {@example core/pipes/ts/async_pipe/async_pipe_example.ts region='AsyncPipeObservable'} */ @Pipe({name: 'async', pure: false}) @Injectable() diff --git a/modules/@angular/examples/core/pipes/ts/async_pipe/async_pipe_example.ts b/modules/@angular/examples/core/pipes/ts/async_pipe/async_pipe_example.ts index ea62e8840df4f..e27ce35fe9ffc 100644 --- a/modules/@angular/examples/core/pipes/ts/async_pipe/async_pipe_example.ts +++ b/modules/@angular/examples/core/pipes/ts/async_pipe/async_pipe_example.ts @@ -2,7 +2,7 @@ import {Component, provide} from '@angular/core'; import {bootstrap} from '@angular/platform-browser'; import {Observable, Subscriber} from 'rxjs/Rx'; -// #docregion AsyncPipe +// #docregion AsyncPipePromise @Component({ selector: 'async-example', template: `