ionic serve
,一切正常。
我有一个viewReport页面,该页面打开一个名为viewModal页面的模式。
我创建了一个管道,当我在viewModal.module.ts中调用该管道时,它给出了错误。 Stack Overflow的某人指导我将其添加到viewReport.module.ts页面中。我做到了,它奏效了。
但是现在当我使用ionic build --prod
进行生产构建时,它给出了错误:
ERROR in The pipe 'safe2' could not be found ("
<ion-text>
{{daily_report_desc }}
<span [innerHtml]="[ERROR ->]daily_report_desc | safe2: 'html'">{{daily_report_desc}}</span>
</ion-text>
<ion-text>
")
[ERROR] An error occurred while running subprocess ng.
...
]的代码> viewReport.module.ts
import { Safe2Pipe } from './../pipes/safepipe2/safe2.pipe'; @NgModule({ imports: [ CommonModule, FormsModule, IonicModule, ViewdailyreportPageRoutingModule ], declarations: [ViewdailyreportPage,ShortenPipe,ViewdreportmodalPage,SafePipe,Safe2Pipe], entryComponents: [ViewdreportmodalPage], exports:[Safe2Pipe] }) export class ViewdailyreportPageModule {} ...
]的代码>
viewModal.page.html
在app.module.ts中添加了safe2pipe,请参见下图,现在当我打开viewReport页面[打开viewModal页面。]时,它给出了错误-<ion-text> {{daily_report_desc }} <span [innerHtml]="daily_report_desc | safe2: 'html'">{{daily_report_desc}}</span> </ion-text>
ionic serve
一切正常,但ionic build --prod
给出错误。编辑:: 1
"): ng:///ViewReportPageModule/ViewModalPage.html@18:25
The pipe 'safe2' could not be found ("
<ion-text>
{{daily_report_desc }}
<span [innerHtml]="[ERROR ->]daily_report_desc | safe2: 'html'">{{daily_report_desc}}</span>
</ion-text>
编辑:: 2
safe2pipe.ts代码
import { Pipe, PipeTransform } from '@angular/core'; import { DomSanitizer, SafeHtml, SafeStyle, SafeScript, SafeUrl, SafeResourceUrl } from '@angular/platform-browser'; @Pipe({ name: 'safe2' }) export class Safe2Pipe implements PipeTransform { constructor(protected sanitizer: DomSanitizer) {} public transform(value: any, type: string): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl { switch (type) { case 'html': return this.sanitizer.bypassSecurityTrustHtml(value); case 'style': return this.sanitizer.bypassSecurityTrustStyle(value); case 'script': return this.sanitizer.bypassSecurityTrustScript(value); case 'url': return this.sanitizer.bypassSecurityTrustUrl(value); case 'resourceUrl': return this.sanitizer.bypassSecurityTrustResourceUrl(value); default: throw new Error(`Invalid safe type specified: ${type}`); } } }
当我做离子饮料时,一切工作都很好。我有一个viewReport页面,该页面打开一个名为viewModal的模态页面。我创建了一个管道,当我在viewModal.module.ts中调用该管道时,它是...
这里是堆叠闪电战:https://stackblitz.com/edit/ionic-c7zfbm
这些步骤是:-创建模态(与模块)-在模态模块上导入管道-在app.module上导入模态模块-将模式页面放在app.module的entryComponents上。-在模式html上调用管道
[请注意,离子炸弹已经过时了,为了工作,我做了一些解决方法。要查看内容,请检查并查找html代码。