safe.pipe.ts
import { Pipe, PipeTransform } from "@angular/core";
import { DomSanitizer } from "@angular/platform-browser";
/**
* safe
* urlangular iframeurl
*
* @export
* @class SafePipe
* @implements {PipeTransform}
*/
@Pipe({
name: "safe"
})
export class SafePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) { }
//Angular 2 DomSanitizerurl
transform(url): any {
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
}
pipe.module.ts
import { NgModule } from "@angular/core";
import {CommonModule} from "@angular/common";
import {SafePipe} from "./safe.pipe"; // <---
@NgModule({
declarations:[SafePipe], // <---
imports:[CommonModule],
exports:[SafePipe] // <---
})
export class PipesModule {}
app.module.ts
import { NgModule } from "@angular/core";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { RouterModule } from "@angular/router";
import { PipesModule } from "@/pipe/pipe.module";
import { ComponentsModule } from "@/components/components.module";
import { LayoutsModule } from "@/layouts/layouts.module";
import { ApiService } from "@/services/api.service";
import { UtilService } from "@/services/util.service";
import { Globals } from "@/services/globals.service";
import { AppComponent } from "./app.component";
import { AppRoute } from "./app.route";
@NgModule({
bootstrap: [
AppComponent,
],
declarations: [
AppComponent,
],
imports: [
PipesModule,
BrowserAnimationsModule,
ComponentsModule,
LayoutsModule,
RouterModule.forRoot(AppRoute, { onSameUrlNavigation: "reload" }),
],
providers: [
ApiService,
UtilService,
Globals
],
})
export class AppModule { }
use pipes to report errors in the page html