简体   繁体   English

Ionic-3找不到管道

[英]Ionic-3 Can't find Pipe

I have just upgraded to Ionic 3.0.1 so I can use LazyLoading , and since that I can't use my custom Pipes : 我刚刚升级到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;
  }
}

and in app.module.ts I have added it to the declarations : app.module.ts我已将其添加到声明中:

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

now when am trying to use it in the html template it errors: 现在当我试图在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

is there anything I'm missing here? 这里有什么我想念的吗?

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 所以我通过制作一个PipesModule修复这个问题,我将自定义Pipes导入到其中,然后将其导入页面module.ts中我想要使用它

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

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

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

and then in the page | 然后在页面中| HomePage as an example: HomePage为例:

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! 它确实工作正常,不确定这是否正确,但它工作正常,如果有更好的方法请告诉我...谢谢!

What you need to do is just import the PipesModule (line 12 in below snippet) in to your every page.module.ts (ie home.moodule.ts) file.... 你需要做的就是将PipesModule (下面的代码片段12) 导入到你的每个page.module.ts(即home.moodule.ts)文件....

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { LoginPage } from './login';
import { PipesModule } from '../../pipes/pipes.module';

@NgModule({
    declarations: [
        LoginPage,
    ],
    imports: [
        IonicPageModule.forChild(LoginPage),
        PipesModule
    ]
})
export class LoginPageModule { }

This worked for me. 这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM