|
1 | 1 | /** |
2 | 2 | * To create a Pipe, you must implement this interface. |
3 | 3 | * |
4 | | - * Angular invokes the `transform` method with the subject as the `value` argument and any |
5 | | - * parameters in the `args` Array. |
| 4 | + * Angular invokes the `transform` method with the value of a binding |
| 5 | + * as the first argument, and any parameters as the second argument in list form. |
6 | 6 | * |
7 | 7 | * ## Syntax |
8 | 8 | * |
9 | | - * `subject | pipeName[:arg0[:arg1...]]` |
| 9 | + * `value | pipeName[:arg0[:arg1...]]` |
10 | 10 | * |
11 | 11 | * ## Example |
12 | 12 | * |
13 | | - * The `RepeatPipe` below repeats the subject as many times as indicated by the first argument: |
| 13 | + * The `RepeatPipe` below repeats the value as many times as indicated by the first argument: |
14 | 14 | * |
15 | 15 | * ``` |
16 | | - * @Pipe({name: 'repeat'}) |
17 | | - * class RepeatPipe implements PipeTransform { |
18 | | - * |
19 | | - * transform(value: any, args: any[] = []) { |
20 | | - * if (isBlank(args) || args.length == 0) { |
21 | | - * throw new BaseException('limitTo pipe requires one argument'); |
22 | | - * } |
| 16 | + * import {Pipe, PipeTransform} from 'angular2/angular2'; |
23 | 17 | * |
24 | | - * let times: number = args[0]; |
25 | | - * |
26 | | - * return value.repeat(times); |
27 | | - * } |
| 18 | + * @Pipe({name: 'repeat'}) |
| 19 | + * export class RepeatPipe implements PipeTransform { |
| 20 | + * transform(value: any, args: any[] = []) { |
| 21 | + * if (args.length == 0) { |
| 22 | + * throw new Error('repeat pipe requires one argument'); |
| 23 | + * } |
| 24 | + * let times: number = args[0]; |
| 25 | + * return value.repeat(times); |
| 26 | + * } |
28 | 27 | * } |
29 | 28 | * ``` |
30 | 29 | * |
31 | 30 | * Invoking `{{ 'ok' | repeat:3 }}` in a template produces `okokok`. |
| 31 | + * |
| 32 | + * See full working example: http://plnkr.co/edit/f5oyIked9M2cKzvZNKHV?p=preview |
| 33 | + * |
32 | 34 | */ |
33 | 35 | export interface PipeTransform { transform(value: any, args: any[]): any; } |
34 | 36 |
|
|
0 commit comments