如何解决找不到管道“安全”
我已将应用升级到 Ionic 5,但我一直收到“找不到管道‘安全’”消息,即使它在 Ionic 3 代码中运行良好。
我尝试了大量不同帖子的许多不同组合,但尽管 Webstorm 说它可以找到安全的,但当我使用 ionic serve 运行应用程序时,我一直在浏览器中收到未找到的消息。
感谢您对以下代码可能存在的问题提出任何意见。
安全模块是:
// Angular Modules
import { DomSanitizer,SafeHtml,SafeResourceUrl,SafeScript,SafeStyle,SafeUrl } from "@angular/platform-browser";
import { Pipe,PipeTransform } from "@angular/core";
@Pipe({name: 'safe'})
export class SafePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
public transform(value: any,type: string): SafeHtml | SafeResourceUrl | SafeScript | SafeStyle | SafeUrl {
switch (type) {
case 'html':
return this.sanitizer.bypassSecurityTrustHtml(value);
break;
case 'resourceUrl':
return this.sanitizer.bypassSecurityTrustResourceUrl(value);
break;
case 'script':
return this.sanitizer.bypassSecurityTrustScript(value);
break;
case 'style':
return this.sanitizer.bypassSecurityTrustStyle(value);
break;
case 'url':
return this.sanitizer.bypassSecurityTrustUrl(value);
break;
default:
throw new Error(`Invalid safe type specified: ${type}`);
break;
}
}
}
共享模块为:
// Angular Modules
import { CommonModule } from '@angular/common';
import { NgModule } from "@angular/core";
// Services
import { SafePipe } from "../safe-pipe/safe.pipe";
@NgModule({
imports: [
CommonModule
],exports: [
SafePipe
],declarations: [
SafePipe
],})
export class AppPipes {}
模块是:
// Angular Modules
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
// Ionic Modules
import { IonicModule } from '@ionic/angular';
// Pages
import { OnboardPage } from './onboard.page';
// Services
import { AppPipes } from "../../utils/app-pipes/app-pipes.util";
// Other Modules
import { OnboardPageRoutingModule } from './onboard-routing.module';
@NgModule({
imports: [
AppPipes,CommonModule,IonicModule,OnboardPageRoutingModule,],declarations: [OnboardPage]
})
export class OnboardPageModule {}
app.module 是:
import { AppPipes } from "./utils/app-pipes/app-pipes.util";
@NgModule({
declarations: [
...
],imports: [
AppPipes,providers: [
AppPipes,SafePipe,]
})
export class AppModule {
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。