Answers for "use pipe in angular"

1

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>
Posted by: Guest on February-13-2021
0

use of pipe

import {Observable, range} from 'rxjs';
import {map, filter} from 'rxjs/operators';

const source$: Observable<number> = range(0, 10);

source$.pipe(
    map(x => x * 2),
    filter(x => x % 3 === 0)
).subscribe(x => console.log(x));
Posted by: Guest on September-17-2021

Browse Popular Code Answers by Language