【问题标题】:angular imported pipe not recognized角进口管无法识别
【发布时间】:2020-02-02 05:42:44
【问题描述】:

我正在尝试在我的个人培训项目中使用以下pipe,按照我使用 npm 安装库的规范,我可以在 ng 模块文件夹中看到它

然后我尝试在我的app.module 中添加NgPipesModule,如下所示

import {NgPipesModule} from 'ngx-pipes';


@NgModule({
  imports: [
    BrowserModule,
    BoxingSharedModule,
    BoxingCoreModule,
    BoxingHomeModule,
    NgPipesModule,
    // jhipster-needle-angular-add-module JHipster will add new module here
    BoxingEntityModule,
    BoxingAppRoutingModule
  ],
  declarations: [JhiMainComponent, NavbarComponent, ErrorComponent, PageRibbonComponent, ActiveMenuDirective, FooterComponent],
  providers: [
    {

我相信这应该足以使用filterBy 管道!!!

这就是我使用它的方法

 <tr *ngFor="let boxer of boxers | filterBy: [searchFilter]: searchValue.value ;trackBy: trackId">

过滤器值由此提供:

                    <input type="text" class="form-control" placeholder="Search"
                        aria-label="Search" aria-describedby="basic-addon2" #searchValue>
                    <div class="input-group-append" (click)="onButtonGroupClick($event)">
                        <button class="btn btn btn-outline-primary" type="button" value="fullName">FullName</button>
                        <button class="btn btn btn-outline-primary" type="button" value="phone">Phone Number</button>
                        <button class="btn btn btn-outline-primary" type="button" value="birthDate">Birth Date</button>
                    </div>

浏览器控制台日志显示没有管道解析如下:

ERROR 错误:未捕获(承诺):错误:模板解析错误: 找不到管道 'filterBy' ("1)" [infiniteScrollDisabled]="page >= links['last']" [infiniteScrollDistance]="0"> ]oxer of boxers | filterBy: [searchFilter]: searchValue.value ;trackBy: trackId"> = links['last']" [infiniteScrollDistance]="0"> ] 拳击手 | filterBy: [searchFilter]: searchValue.value ;trackBy: trackId">

我不知道我在这里错过了什么?

你应该知道我在使用 JHipster

【问题讨论】:

    标签: javascript angular typescript ecmascript-6 single-page-application


    【解决方案1】:

    您的配置是正确的,但我不确定您的组件位置。

    要让您的组件使用该管道,您还需要将该组件添加到 declarations 数组中。您要使用管道的组件必须在您导入管道的同一模块中

    【讨论】:

    • 谢谢,它现在可以工作了,我在声明组件的同一个功能模块中添加了管道
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-19
    • 2019-03-29
    • 1970-01-01
    • 2019-09-18
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    相关资源
    最近更新 更多