import {Component} from 'angular2/core'; import {ExponentialStrengthPipe} from './exponential-strength'; @Component({ selector: 'appTest',template: ` <h2>Power Booster</h2> <p> Super power boost: {{10 | exponentialStrength : 10}} </p> `,pipes: [ExponentialStrengthPipe] }) export class App { }
/** * Created by dell on 2016/9/8. */ import {Pipe,PipeTransform} 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 implements PipeTransform { transform(value:number,args:string[]) : any { return value + parseInt(args[0]); } }原文链接:https://www.f2er.com/angularjs/148890.html