angular-cn/public/docs/_examples/pipes/ts/app/random-pipe.component.ts
joeeames 5b27178083 docs(pipes) clarify impure pipes; explain missing filter/orderBy pipes
adds flying-heroes example and its test
adds random-pipe example
2016-03-23 00:02:04 -07:00

25 lines
596 B
TypeScript

import {Component} from 'angular2/core';
import {Pipe, PipeTransform} from 'angular2/core';
// #docregion pipe
// Pure pipe
@Pipe({ name: 'randomizer' })
export class RandomizerPipe implements PipeTransform {
// Impure function
transform() { return Math.random() * 10 ;}
}
// #enddocregion pipe
@Component({
selector: 'random-pipe',
template: `
<h2>Random Pipe (pure pipe/impure function)</h2>
<input #box (input)="0">
<p>Input value: {{box.value}}</p>
<p>Random pipe output: {{box.value | randomizer}}</p>
`,
pipes: [RandomizerPipe]
})
export class RandomPipeComponent {
}