According to the angular docs:
If you choose to inject your pipe into a class, you must provide it in the providers array of your NgModule.
Given exponential-strength.pipe.ts:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'exponentialStrength' })
export class ExponentialStrengthPipe implements PipeTransform {
transform(value: number, exponent?: number): number {
return Math.pow(value, isNaN(exponent) ? 1 : exponent);
}
}
I am able to use this custom pipe in a template by adding the declaration to app.module.ts:
@NgModule({
declarations: [
AppComponent,
ExponentialStrengthPipe
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
E.G. in app.component.html
<div>
{{ 2 | exponentialStrength:10 }}
</div>
I'm confused by Angular's documentation. It doesn't mention the need to add the custom pipe to declarations in the documentation. The documentation only mentions providers.
Is it useful in some cases to inject a pipe when the declaration works just fine? I'm having trouble imagining a use case where I would actually put a pipe into providers array. And would I still need to define the custom pipe in declarations in such a case?