Архитектура My Angular состоит из 3 модулей.
AppModule
(там, где находится предисловие и логика приложения) CoreModule
(Содержит мои службы для доступа к API) SharedModule
(Содержит мои модели, каналы, директивы и т. Д.)
Я хочу добавить новый канал в свой SharedModule
, поэтому я создаю его изатем добавьте его в поля declarations
и exports
декоратора SharedModule
* NgModule
.
Затем в моем AppModule
я импортирую SharedModule
и должен иметь доступ кмои трубыНо вот вещь, я не могу.Вместо этого у меня появляется следующая ошибка:
Uncaught Error: Ошибки синтаксического анализа шаблона: не удалось найти 'positionposition' канала
Код:
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 { }
Редактировать: Добавить код моего компонента:
рейтинга.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>();
}
}
рейтинг.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>
Я что-то пропустил?