Ionic-3 找不到管道 [英] Ionic-3 Can't find Pipe

查看:27
本文介绍了Ionic-3 找不到管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have just upgraded to Ionic 3.0.1 so I can use LazyLoading , and since that I can't use my custom 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 中,我将它添加到声明中:

and in app.module.ts I have added it to the declarations :

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

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

now when am trying to use it in the html template it errors:

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

这里有什么我遗漏的吗?

is there anything I'm missing here?

推荐答案

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

so I fixed this issue by making a PipesModule where I import my custom Pipes into, then import it in the page module.ts that I wanna use it on

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

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

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

然后在页面中 |HomePage 为例:

and then in the page | HomePage as an example:

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 { }

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

and it did work fine , not sure if this is the correct way or not , but it worked fine, please let me know if there is a better way... thanks!

这篇关于Ionic-3 找不到管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆