菜鸟实验中 ing........(自定义管道)
第一步:创建一个文件夹,专门用于写pipe的,名字随意
第二步:创建一个文件
![](https://img.haomeiwen.com/i9374643/523f17e347514a6b.png)
第三步:开始编写内容啦
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里面引入写的管道哦
![](https://img.haomeiwen.com/i9374643/4cc9abf275746dc0.png)
第五步:在你要应用的html里面
![](https://img.haomeiwen.com/i9374643/727b080c3716a90f.png)
网友评论