这个问题与使用深度链接和延迟加载Ionic 3时如何在管道文件中使用提供程序非常相似?但在这个问题上,我们不使用提供者。
我有2个延迟加载页面Page1和Page2,以及HomePage作为根页面。另外,MyPipe文件是管道文件。如下所示。我想在懒惰中使用此管道文件加载文件Page1,Page2和HomePage
情况1:如果我Pipe
仅在app.module
然后发生以下错误
运行时错误,未捕获(承诺):错误:模板解析错误:找不到管道'myPipe'(“ {{[ERROR->]'test1'| myPipe}}”):ng:/// Page1PageModule / Page1Page .html @ 16:2错误:模板解析错误:找不到管道'myPipe'(“ {{[ERROR->]'test1'| myPipe}}”):
Case 2
:如果我将Pipe
文件导入到Page1Module
和Page2Module
然后发生以下错误
运行时错误未发现(承诺):错误:类型MyPipe是2个模块的声明的一部分:Page1PageModule和Page2PageModule!请考虑将MyPipe移至导入Page1PageModule和Page2PageModule的更高模块。您还可以创建一个新的NgModule,该导出并包含MyPipe,然后在Page1PageModule和Page2PageModule中导入该NgModule。错误:类型MyPipe是2个模块的声明的一部分:Page1PageModule和Page2PageModule!请考虑将MyPipe移至导入Page1PageModule和Page2PageModule的更高模块。您还可以创建一个新的NgModule,该导出并包含MyPipe,然后在Page1PageModule和Page2PageModule中导入该NgModule。
感谢您的建议。
这很简单。这是我的工作流程。
我pipe
用这个创建CLI
:ionic generate pipe MyFilter
然后它将pipes.module.ts
自动创建。
之后,我将import
其放入module
如下所示的延迟加载页面中。
member.module.ts
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { MemberPage } from './member';
import { PipesModule } from '../../pipes/pipes.module';
@NgModule({
declarations: [
MemberPage,
],
imports: [
IonicPageModule.forChild(MemberPage),
PipesModule <-- here
],
})
export class MemberPageModule { }
pipe
也可以正常工作:)本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句