在角度5中找不到管道'limitTo'问题

时间:2018-04-12 09:29:03

标签: angular5

我创建了一个自定义管道模块并将其导入我的自定义模块中,但它无法正常工作

limit.pipe

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'limitTo'
})
export class RcycLimitPipe implements PipeTransform {

  transform(value: any, args?: any): any {
    let limit = args ? parseInt(args, 10) : 10;
    let trail = '...';

    return value.length > limit ? value.substring(0, limit) + trail : value;
  }

}

limit.pipe.module

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RcycLimitPipe } from './rcyc-limit.pipe';
@NgModule({
    imports: [
        CommonModule
    ],
    declarations: [
        RcycLimitPipe
    ],
    exports: [
        RcycLimitPipe
    ]
})
export class RcycLimitPipeModule { }

然后我在我的自定义模块中导入它。

import { NgModule } from '@angular/core';
import { ChannelsComponent }   from './rcyc-channels.component';
import { routing } from './rcyc-channels.routing';
import { CommonModule } from '@angular/common';
import { NgxCarouselModule } from "ngx-carousel";
import { RcycChannelsService } from "./rcyc-channels.service";
import { RcycLimitPipeModule } from "../../rcyc-pipes/rcyc-limit/rcyc-limit.module";
import { RcycDefaultImagePipeModule } from '../../rcyc-pipes/rcyc-default-image/rcyc-default-image.module';
@NgModule({
  imports: [routing,CommonModule,NgxCarouselModule,RcycLimitPipeModule,RcycDefaultImagePipeModule],
  declarations: [ChannelsComponent],
   providers: [RcycChannelsService]
})
export class ChannelsModule {}

但它仍然显示错误,告诉我们找不到'限制和'defaultimage'。

这是我的错误

enter image description here

这里的问题是什么?请帮帮我

1 个答案:

答案 0 :(得分:0)

你真的需要一个单独的管道模块吗?毕竟,您实际上只是导入NgModuleCommonModule(您还在主模块中导入)和RcycLimitPipe

您只需完全删除limit.pipe.module,在主模块中导入RcycLimitPipe,然后将其添加到declarations