Skip to content

Commit d9776b4

Browse files
jeffbcrossIgorMinar
authored andcommitted
docs(core): add docs for PipeTransform interface
1 parent 53412a7 commit d9776b4

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

modules/angular2/src/core/change_detection/pipe_transform.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
/**
22
* To create a Pipe, you must implement this interface.
33
*
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.
66
*
77
* ## Syntax
88
*
9-
* `subject | pipeName[:arg0[:arg1...]]`
9+
* `value | pipeName[:arg0[:arg1...]]`
1010
*
1111
* ## Example
1212
*
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:
1414
*
1515
* ```
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';
2317
*
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+
* }
2827
* }
2928
* ```
3029
*
3130
* Invoking `{{ 'ok' | repeat:3 }}` in a template produces `okokok`.
31+
*
32+
* See full working example: http://plnkr.co/edit/f5oyIked9M2cKzvZNKHV?p=preview
33+
*
3234
*/
3335
export interface PipeTransform { transform(value: any, args: any[]): any; }
3436

0 commit comments

Comments
 (0)