angularjs 管道@pipe

菜鸟实验中 ing........(自定义管道)

第一步:创建一个文件夹,专门用于写pipe的,名字随意

第二步:创建一个文件

第三步:开始编写内容啦

import{Pipe,PipeTransform}from'@angular/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'})

exportclassExponentialStrengthPipeimplementsPipeTransform{

transform(value:number,exponent:string):number{

letexp=parseFloat(exponent);

returnMath.pow(value,isNaN(exp)?1:exp);

}

}


第四部:记得在app.module里面引入写的管道哦

第五步:在你要应用的html里面

你可能感兴趣的:(angularjs 管道@pipe)