В первом: Angular2: custom pipe could not be found это не помогла мне в любом случае .. У меня есть следующая проблема:Угловые 2 пользовательских трубы не найдены
Труба:
import { Pipe, PipeTransform } from "@angular/core";
import { DecimalPipe} from "@angular/common";
@Pipe({
name: "ToNumberPipe"
})
export class ToNumberPipe extends DecimalPipe implements PipeTransform {
// this allows to pass strings in decimalpipes as well and do nothing if it NAN
public transform(value: string, args: string): any {
const retNumber = Number(value);
if (isNaN(retNumber)) {
return value;
}
return super.transform(value, args);
}
}
App: модуль
@NgModule(
{
// all components, pipes and directive which are using this module
declarations: [AppComponent, ... all Components go here],
// All modules like forms or http
imports: [...., MainPipeModule],
// all services and other providers
providers: [...all services go here],
bootstrap: [AppComponent]
}
)
export class AppModule {
}
Модуль Pipe
import { NgModule } from "@angular/core";
import {CommonModule} from "@angular/common";
import {ToNumberPipe} from "./shared/pipes/customNumber.pipe";
@NgModule(
{
// all components, pipes and directive which are using this module
declarations: [ToNumberPipe],
imports: [CommonModule],
exports: [ToNumberPipe]
})
export class MainPipeModule {
}
Html код
<span [ngClass]="getClass(rowValue)" class="badge isLink" (click)="selectTask(rowValue.taskId)">{{rowValue.value | ToNumberPipe : "1.0-4"}}</span>
Я пытался добавить трубы непосредственно к app.module, но с тем же результатом ...
zone.js:1 Unhandled Promise rejection: Template parse errors:
The pipe 'ToNumberPipe' could not be found
Кроме того, я попытался удалить аргументы и добавить простую трубу а также ... всегда та же ошибка
Угловое 2 Версия: 2.2.4
Какой компонент содержит код, который использует трубу? Для чего «NgModule» принадлежит этот компонент? –
Все компоненты находятся в одном файле app.module. Прежде чем я разделил его на некоторые модули и подумал, что это может быть проблема с различными модулями. Но это не помогло переместить все части приложения в один модуль. –