无法解析BypassSanitizerPipe的所有参数:(?)

时间:2019-10-01 17:28:42

标签: angular angular7 angular8

我升级到Angular 8,并且在更新所有内容后,我在浏览器上发现了此错误

此处管道代码

import {Pipe, PipeTransform} from '@angular/core';
import {DomSanitizer, SafeHtml} from '@angular/platform-browser';

@Pipe({
    name: 'bypassSanitizer'
})
export class BypassSanitizerPipe implements PipeTransform {

    constructor(private domSanitizer: DomSanitizer) {
    }

    transform(html: string): SafeHtml {
        if (html) {
            return this.domSanitizer.bypassSecurityTrustHtml(html);
        } else {
            return '...';
        }
    }
}

这里是管道模块代码

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BypassSanitizerPipe } from './bypass-sanitizer.pipe';

@NgModule({
    declarations: [
        BypassSanitizerPipe
    ],
    providers: [
        BypassSanitizerPipe
    ],
    imports: [
        CommonModule
    ],
    exports: [
        BypassSanitizerPipe
    ]
})
export class CorePipeModule {

    static forRoot() {
        return {
            ngModule: CorePipeModule,
            providers: [],
        };
    }
}

升级到8之前,一切正常。 我的旧版本是Angular 7 enter image description here 预先感谢

1 个答案:

答案 0 :(得分:0)

我解决了这个问题,只是从管道模块中删除了提供程序

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BypassSanitizerPipe } from './bypass-sanitizer.pipe';

@NgModule({
    declarations: [
        BypassSanitizerPipe
    ],
    imports: [
        CommonModule
    ],
    exports: [
        BypassSanitizerPipe
    ]
})
export class CorePipeModule {

    static forRoot() {
        return {
            ngModule: CorePipeModule,
            providers: [],
        };
    }
}