From 2ab8c59ad51768a37a11cf6a9f16c44e265dcaf2 Mon Sep 17 00:00:00 2001 From: Jeff Cross Date: Wed, 9 Sep 2015 14:56:48 -0700 Subject: [PATCH] docs(pipes): improve docs for async pipe Closes #4104 --- modules/angular2/src/core/pipes.ts | 2 +- modules/angular2/src/core/pipes/async_pipe.ts | 25 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/modules/angular2/src/core/pipes.ts b/modules/angular2/src/core/pipes.ts index a597f8c891..2b918fe845 100644 --- a/modules/angular2/src/core/pipes.ts +++ b/modules/angular2/src/core/pipes.ts @@ -1,7 +1,7 @@ /** * @module * @description - * This module provides advanced support for extending change detection. + * This module provides a set of common Pipes. */ export {AsyncPipe} from './pipes/async_pipe'; diff --git a/modules/angular2/src/core/pipes/async_pipe.ts b/modules/angular2/src/core/pipes/async_pipe.ts index 43de5c26aa..6f2203783a 100644 --- a/modules/angular2/src/core/pipes/async_pipe.ts +++ b/modules/angular2/src/core/pipes/async_pipe.ts @@ -36,28 +36,27 @@ var _observableStrategy = new ObservableStrategy(); /** - * Implements async bindings to Observable and Promise. + * 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. * * # Example + * The example below binds the `time` Observable to the view. Every 500ms, the `time` Observable + * updates the view with the current time. * - * In this example we bind the description observable to the DOM. The async pipe will convert an - *observable to the - * latest value it emitted. It will also request a change detection check when a new value is - *emitted. - * - * ``` + * import {Observable} from 'angular2/core'; * @Component({ - * selector: "task-cmp", - * changeDetection: ChangeDetectionStrategy.OnPush + * selector: "task-cmp" * }) * @View({ - * template: "Task Description {{ description | async }}" + * template: "Time: {{ time | async }}" * }) * class Task { - * description:Observable; + * time = new Observable(observer => { + * setInterval(_ => + * observer.next(new Date().getTime(), 500); + * }); * } - * - * ``` */ @Pipe({name: 'async', pure: false}) @Injectable()