KarolDepka
KarolDepka

Reputation: 8628

Angular: Rules on when to make something a custom pipe vs component

Any rules on when to use a custom pipe and when to use a custom component?

Could those be the rules of thumb (below) ?

Documentation does not seem to answer this question directly: https://angular.io/docs/ts/latest/guide/pipes.html

Could pipes be considered «poor man's components?»


Are there some advantages of pipes over components?

My guesses:


Does this statement (which is a guess written by me) hold true?

Everything that can be done with a pipe,
can be done (though perhaps at a higher cost) with a component as well?

Upvotes: 1

Views: 844

Answers (1)

DeborahK
DeborahK

Reputation: 60518

According to that same documentation:

Pipes transform displayed values within a template

So if you are transforming displayed values, such as formatting a date or filtering a list, then a pipe makes sense.

If you are displaying HTML, use a component.

And the answer from 2015 for using innerHtml is not considered "best practices" and should be limited to only a last resort.

Upvotes: 1

Related Questions