python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
6

What Is Pipe? Why use Pipes?

What Is Pipe?
Pipes transform displayed values within a template.

Use the @Pipe annotation to declare that a given class is a pipe. A pipe class must also implement a PipeTransform interface.

The @Pipe decorator allows you to define the pipe name that is globally available for use in any template in the across Angular apps.

Pipe class implements the “PipeTransform” interfaces transform method that accepts an input value and returns the transformed result.

There will be one additional argument to the transform method for each parameter passed to the pipe.

The CLI commons for generate Pipe -
ng g pipe PipeName
//OR
ng generate pipe PipeName


Pipe decorator and metadata –
@Pipe({
  name: string
  pure?: boolean
})

The pipe name is used for template bindings.
To use the pipe you must set a reference to this pipe class in the module.

Why use Pipes?
Sometimes, the data is not displayed in the well format on the HTML templates that times were using pipes.

You also can execute a function in the HTML template to get its returned value.

For example - If you want to display a credit card number on your web apps - you can't display the whole number on your web app - you should write a custom logic to display card number as like ****-****-2485 using your custom pipe.

For more detail kindly refer the -

https://www.code-sample.com/2018/05/angular-5-6-7-pipes-decorator.html
ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions