docs(core): add docs for PipeTransform interface
This commit is contained in:
parent
53412a71e5
commit
d9776b4112
|
@ -1,34 +1,36 @@
|
|||
/**
|
||||
* To create a Pipe, you must implement this interface.
|
||||
*
|
||||
* Angular invokes the `transform` method with the subject as the `value` argument and any
|
||||
* parameters in the `args` Array.
|
||||
* Angular invokes the `transform` method with the value of a binding
|
||||
* as the first argument, and any parameters as the second argument in list form.
|
||||
*
|
||||
* ## Syntax
|
||||
*
|
||||
* `subject | pipeName[:arg0[:arg1...]]`
|
||||
* `value | pipeName[:arg0[:arg1...]]`
|
||||
*
|
||||
* ## Example
|
||||
*
|
||||
* The `RepeatPipe` below repeats the subject as many times as indicated by the first argument:
|
||||
* The `RepeatPipe` below repeats the value as many times as indicated by the first argument:
|
||||
*
|
||||
* ```
|
||||
* import {Pipe, PipeTransform} from 'angular2/angular2';
|
||||
*
|
||||
* @Pipe({name: 'repeat'})
|
||||
* class RepeatPipe implements PipeTransform {
|
||||
*
|
||||
* transform(value: any, args: any[] = []) {
|
||||
* if (isBlank(args) || args.length == 0) {
|
||||
* throw new BaseException('limitTo pipe requires one argument');
|
||||
* }
|
||||
*
|
||||
* let times: number = args[0];
|
||||
*
|
||||
* return value.repeat(times);
|
||||
* }
|
||||
* export class RepeatPipe implements PipeTransform {
|
||||
* transform(value: any, args: any[] = []) {
|
||||
* if (args.length == 0) {
|
||||
* throw new Error('repeat pipe requires one argument');
|
||||
* }
|
||||
* let times: number = args[0];
|
||||
* return value.repeat(times);
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* Invoking `{{ 'ok' | repeat:3 }}` in a template produces `okokok`.
|
||||
*
|
||||
* See full working example: http://plnkr.co/edit/f5oyIked9M2cKzvZNKHV?p=preview
|
||||
*
|
||||
*/
|
||||
export interface PipeTransform { transform(value: any, args: any[]): any; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue