Angular 4 Pipe Not Found Template

I am trying to use a custom channel in my project Angular 4. I can’t understand why the compiler does not recognize my pipe in the component template.

QFormat handset

@Pipe({  name: 'qFormat'})
export class QFormatPipe implements PipeTransform {...}

Sharedmodule

@NgModule({
    declarations: [QFormatPipe],
    exports: [QFormatPipe]
})
export class SharedModule { }

Featuremodule

@NgModule({
  imports: [SharedModule],
  declarations: [MyComponent]
})
export class FeatureModule{ }

MyComponent.html

<div>{{someProp | qformat}}</div>
                  ^^^^^^^

The pattern causes an error:

Angular: could not find 'qformat' pipe

Did I miss something?

+4
source share
3 answers

The reason he cannot find the handset is because you registered the channel as "qFormat" with capital F, but in HTML you have "qformat" with lowercase f. This is why an error occurs. Your general registration of modules and import / export are fully included. HTML should be:

<div>{{someProp | qFormat}}</div>

Hope this helps!

+3

, @NgModule

+1

, CLI app.module, , , .

, :

( app.module.ts). , ​​ pipe: , 'ng g module pipes/pipe-common'

'ng g pipe myPipeExample`,

: [myPipeExamplePipe]

: [myPipeExamplePipe]

, , .

This question contains some very helpful answers.

+1
source

Source: https://habr.com/ru/post/1680759/


All Articles