angular-docs-cn/public/docs/_examples/pipes/ts/app/exponential-strength.pipe.ts
2015-12-13 00:57:14 -08:00

19 lines
453 B
TypeScript

// #docregion
import {Pipe} from 'angular2/core';
/*
* Raise the value exponentially
* Takes an exponent argument that defaults to 1.
* Usage:
* value | exponentialStrength:exponent
* Example:
* {{ 2 | exponentialStrength:10}}
* formats to: 1024
*/
@Pipe({name: 'exponentialStrength'})
export class ExponentialStrengthPipe {
transform(value:number, args:string[]) : any {
return Math.pow(value, parseInt(args[0] || '1', 10));
}
}