Monday, July 9, 2018

Pipes in Angular

Pipe: Pipes are easy way to encapsulate and share common display data. With the help of we can enrich the views and format display data.

Type of Pipes:
     1. Pure Pipe
     2. Impure Pipe

We can make pure and impure pipe's by setting pure: true or false. By default it is true.

@Pipe({
          name: 'formatcurrency',
          pure: true
})

Pure Pipe:
     When true, it means that the transform() method is invoke only when its input argument change.
 
Impure Pipe: 
     When false, it means that the method invoke every change-detection cycle. even if the argument are not change. Impure pipe called in every keystroke or move move, so be careful to implement it.

Chaining Pipes: 
      We can chain pipes together to get desired output. Like:
      {{ currencyname | formatcurrency | uppercase }}

Here output is: INR

No comments:

Post a Comment