angular using pipes in a service code example
Example: angular pipes
//component.ts file:
import {Pipe, PipeTransform} from '@angular/core';
@Pipe ({
name : 'sqrt'
})
export class SqrtPipe implements PipeTransform {
transform(val : number) : number {
return Math.sqrt(val);
}
}
//import SqrtPipe inside your module.ts ,
import { SqrtPipe } from './app.sqrt';
declarations: [
SqrtPipe,
],
//then you can use this pipe in component.html file.
// <h2>Square root of 625 is: {{625 | sqrt}}</h2>