angular - Ionic-3 找不到管道

标签 angular typescript ionic-framework ionic3

我刚刚升级到 Ionic 3.0.1 所以我可以使用 LazyLoading ,从那以后我不能使用我的自定义 Pipes :

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

@Pipe({
  name: 'StripHTML'
})

export class StripHTML implements PipeTransform {

  transform(value, args) {
    let striped = value.replace(/(<([^>]+)>)/g, "");

    if (args != null) {
      if (args.split != null) {
        striped = striped.split(args.split);
        if (args.index != null) {
          striped = striped[args.index];
        }
      }
    }

    return striped;
  }
}

app.module.ts 中,我已将其添加到声明中:

@NgModule({
  declarations: [
    ........,
    StripHTML
  ],
...

现在当我尝试在 html 模板中使用它时出现错误:

core.es5.js:1085 ERROR Error: Uncaught (in promise): Error: Template parse errors:
The pipe 'StripHTML' could not be found ("
          <ion-card-content>
            <ion-card-title style="font-size: 100%">
              {{ [ERROR ->]product.title | StripHTML }}
            </ion-card-title>
          </ion-card-content>
"): ng:///HomeModule/Home.html@33:17

这里有什么我遗漏的吗?

最佳答案

所以我通过创建一个 PipesModule 来解决这个问题,我将自定义 Pipes 导入其中,然后将其导入页面 module.ts我想用它

import { NgModule } from '@angular/core';
import { StripHTML } from './strip-html';

@NgModule({
  declarations: [
    StripHTML,
  ],
  imports: [

  ],
  exports: [
    StripHTML
  ]
})
export class PipesModule { }

然后在页面中| 首页为例:

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { Home } from './home';

import { PipesModule } from '../../pipes/pipes.module';

@NgModule({
  declarations: [
    Home,
  ],
  imports: [
    IonicPageModule.forChild(Home),
    PipesModule
  ],
  exports: [
    Home
  ]
})
export class HomeModule { }

它确实工作正常,不确定这是否是正确的方法,但它工作正常,如果有更好的方法请告诉我...谢谢!

关于angular - Ionic-3 找不到管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43299610/

相关文章:

javascript - Angular UI 路由器在更改状态时不执行 Controller 代码

javascript - 如何根据所选选项更改值?

tomcat - 在 nginx 上使用 Angular 2 前端有哪些优势?

javascript - 错误 TS2339 : Property 'checked' does not exist on type 'HTMLElement'

javascript - 尝试使用 html5 拖放创建 "folder-like"gui (Angular 4)

angular - typescript ( Angular )日期时间到日期

javascript - 使用 Knockout 将 TypeScript 类作为 ViewModel?

javascript - 在 ionic2+bootstrap4 中滚动时,粘性页脚随屏幕一起移动

angular - 如何直接从 formControl 获取验证器?

angular - 如何由于另一个模型的字段而隐藏 Formly 表单的字段