user1059939
user1059939

Reputation: 1725

When to use ngOnChanges vs Pipes

So far on my Angular journey, I have not had a great deal of need for pipes.

A common theme so far is that most components have an @Input of some data coming in, which may need some operating on before being used by the template.

This leaves a rather dirty situation:

// data coming in
@Input data: MyDataInterface;

// data after massage, it is this which powers the template
config: MyDataInterfaceAfterMassage;

// the masseuse works in here and creates a new "config" object
ngOnChanges() {

}

But then it occurred to me, I guess I could also do this with Pipes but not sure on where the distinction is made.

Given the choice between ngOnChanges and Pipe, under what circumstance would you use one over the other when relative to binding to the template?

Upvotes: 1

Views: 811

Answers (1)

user4676340
user4676340

Reputation:

Fast and easy : ngOnChanges is used to detect a change from a variable decorated with @Input, and pipes are used to display data that are displayed in a particular format, but their value isn't changed.

Upvotes: 2

Related Questions