My Angular architecture is composed of 3 modules.
AppModule
(where the app prensetation and logic resides)CoreModule
(Contains my services to access API)SharedModule
(Contains my models, pipes, directives, etc...)
I want to add a new pipe in my SharedModule
, so I create it and then add it to the declarations
and exports
fields of the SharedModule
's NgModule
decorator.
Then, in my AppModule
, I import the SharedModule
and should have access to my pipes. But, there the thing, I can't. Instead, I have the following error:
Uncaught Error: Template parse errors: The pipe 'rankingposition' could not be found
There is the code:
rankingposition.pipe.ts
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({ name: 'rankingposition' })
export class RankingPositionPipe implements PipeTransform {
transform(value: any, ...args: any[]) {
// Do stuff
}
}
shared.module.ts
import { NgModule } from "@angular/core";
import { RankingPositionPipe } from "@app/shared/pipes/ranking-position.pipe";
@NgModule({
declarations: [RankingPositionPipe],
exports: [RankingPositionPipe]
})
export class SharedModule {}
app.module.ts
import { NgModule } from '@angular/core';
...
import { SharedModule } from '@app/shared/shared.module';
@NgModule({
declarations: [...],
imports: [
...,
SharedModule
],
providers: [],
bootstrap: [...]
})
export class AppModule { }
Edit: Add my component code:
ranking.component.ts
import { Component } from "@angular/core";
import { CharacterModel } from "@app/shared/models/character.model";
@Component({
selector: 'ranking',
templateUrl: './ranking.component.html'
})
export class RankingComponent {
public characters: Array<CharacterModel>;
constructor() {
this.characters = new Array<CharacterModel>();
}
}
ranking.component.html
<div class="card">
<div class="card-header">
Ranking
</div>
<div class="card-body">
<ul>
<li *ngFor="let character of characters; let i = index">
{{ character.level | rankingposition }}
</li>
</ul>
</div>
</div>
Did I miss something?