diff --git a/index.ts b/index.ts index 0552fb8..d5c0f85 100644 --- a/index.ts +++ b/index.ts @@ -10,6 +10,7 @@ export * from './src/toasty.component'; import { ToastyComponent } from './src/toasty.component'; import { ToastComponent } from './src/toast.component'; +import { SafeHtmlPipe } from './src/shared'; import { ToastyService, ToastyConfig, toastyServiceFactory } from './src/toasty.service'; export let providers = [ @@ -19,7 +20,7 @@ export let providers = [ @NgModule({ imports: [CommonModule], - declarations: [ToastComponent, ToastyComponent], + declarations: [ToastComponent, ToastyComponent, SafeHtmlPipe], exports: [ ToastComponent, ToastyComponent], providers: providers }) diff --git a/src/shared.ts b/src/shared.ts new file mode 100644 index 0000000..226ff36 --- /dev/null +++ b/src/shared.ts @@ -0,0 +1,11 @@ +import { DomSanitizer } from '@angular/platform-browser'; +import { PipeTransform, Pipe } from '@angular/core'; + +@Pipe({ name: 'safeHtml'}) +export class SafeHtmlPipe implements PipeTransform { + constructor(private domSanitized: DomSanitizer) {} + + transform(value: any, ...args: any[]): any { + return this.domSanitized.bypassSecurityTrustHtml(value); + } +} \ No newline at end of file diff --git a/src/toast.component.ts b/src/toast.component.ts index 651bafc..b014465 100644 --- a/src/toast.component.ts +++ b/src/toast.component.ts @@ -15,9 +15,9 @@ import { ToastData } from './toasty.service';
- {{toast.title}} +
- {{toast.msg}} +
` }) diff --git a/tests/toast.component.spec.ts b/tests/toast.component.spec.ts index 1ee0e14..6331ecd 100644 --- a/tests/toast.component.spec.ts +++ b/tests/toast.component.spec.ts @@ -3,6 +3,7 @@ import { TestBed, ComponentFixture } import {ToastData} from '../src/toasty.service'; import {ToastComponent} from '../src/toast.component'; +import {SafeHtmlPipe} from '../src/shared'; describe('ToastComponent', () => { @@ -23,7 +24,7 @@ describe('ToastComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ToastComponent] + declarations: [ToastComponent, SafeHtmlPipe] }); TestBed.compileComponents(); }); diff --git a/tests/toasty.component.spec.ts b/tests/toasty.component.spec.ts index 034715e..aa2fe9e 100644 --- a/tests/toasty.component.spec.ts +++ b/tests/toasty.component.spec.ts @@ -4,6 +4,7 @@ import { TestBed, ComponentFixture } import {ToastyService, ToastData, ToastyConfig} from '../src/toasty.service'; import {ToastyComponent} from '../src/toasty.component'; import {ToastComponent} from '../src/toast.component'; +import {SafeHtmlPipe} from '../src/shared'; describe('ToastyComponent', () => { @@ -37,7 +38,7 @@ describe('ToastyComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ToastComponent, ToastyComponent], + declarations: [ToastComponent, ToastyComponent, SafeHtmlPipe], providers: [ToastyService, ToastyConfig] }); TestBed.compileComponents(); diff --git a/tsconfig.json b/tsconfig.json index 7a478ae..e346ac8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,6 +16,7 @@ }, "files": [ "index.ts", + "./src/shared.ts", "./src/toast.component.ts", "./src/toasty.component.ts", "./src/toasty.service.ts",