10000 feat(html-content): Initial commit · akserg/ng2-toasty@7a0d53f · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 7a0d53f

Browse files
committed
feat(html-content): Initial commit
1 parent a4abe7b commit 7a0d53f

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export * from './src/toasty.component';
1010

1111
import { ToastyComponent } from './src/toasty.component';
1212
import { ToastComponent } from './src/toast.component';
13+
import { SafeHtmlPipe } from './src/shared';
1314
import { ToastyService, ToastyConfig, toastyServiceFactory } from './src/toasty.service';
1415

1516
export let providers = [
@@ -19,7 +20,7 @@ export let providers = [
1920

2021
@NgModule({
2122
imports: [CommonModule],
22-
declarations: [ToastComponent, ToastyComponent],
23+
declarations: [ToastComponent, ToastyComponent, SafeHtmlPipe],
2324
exports: [ ToastComponent, ToastyComponent],
2425
providers: providers
2526
})

src/shared.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DomSanitizer } from '@angular/platform-browser';
2+
import { PipeTransform, Pipe } from '@angular/core';
3+
4+
@Pipe({ name: 'safeHtml'})
5+
export class SafeHtmlPipe implements PipeTransform {
6+
constructor(private domSanitized: DomSanitizer) {}
7+
8+
transform(value: any, ...args: any[]): any {
9+
return this.domSanitized.bypassSecurityTrustHtml(value);
10+
}
11+
}

src/toast.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import { ToastData } from './toasty.service';
1515
<div class="toast" [ngClass]="[toast.type, toast.theme]">
1616
<div *ngIf="toast.showClose" class="close-button" (click)="close($event)"></div>
1717
<div *ngIf="toast.title || toast.msg" class="toast-text">
18-
<span *ngIf="toast.title" class="toast-title">{{toast.title}}</span>
18+
<span *ngIf="toast.title" class="toast-title" [innerHTML]="toast.title | safeHtml"></span>
1919
<br *ngIf="toast.title && toast.msg" />
20-
<span *ngIf="toast.msg" class="toast-msg">{{toast.msg}}</span>
20+
<span *ngIf="toast.msg" class="toast-msg" [innerHtml]="toast.msg | safeHtml"></span>
2121
</div>
2222
</div>`
2323
})

tests/toast.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { TestBed, ComponentFixture }
33

44
import {ToastData} from '../src/toasty.service';
55
import {ToastComponent} from '../src/toast.component';
6+
import {SafeHtmlPipe} from '../src/shared';
67

78
describe('ToastComponent', () => {
89

@@ -23,7 +24,7 @@ describe('ToastComponent', () => {
2324

2425
beforeEach(() => {
2526
TestBed.configureTestingModule({
26-
declarations: [ToastComponent]
27+
declarations: [ToastComponent, SafeHtmlPipe]
2728
});
2829
TestBed.compileComponents();
2930
});

tests/toasty.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { TestBed, ComponentFixture }
44
import {ToastyService, ToastData, ToastyConfig} from '../src/toasty.service';
55
import {ToastyComponent} from '../src/toasty.component';
66
import {ToastComponent} from '../src/toast.component';
7+
import {SafeHtmlPipe} from '../src/shared';
78

89
describe('ToastyComponent', () => {
910

@@ -37,7 +38,7 @@ describe('ToastyComponent', () => {
3738

3839
beforeEach(() => {
3940
TestBed.configureTestingModule({
40-
declarations: [ToastComponent, ToastyComponent],
41+
declarations: [ToastComponent, ToastyComponent, SafeHtmlPipe],
4142
providers: [ToastyService, ToastyConfig]
4243
});
4344
TestBed.compileComponents();

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"files": [
1818
"index.ts",
19+
"./src/shared.ts",
1920
"./src/toast.component.ts",
2021
"./src/toasty.component.ts",
2122
"./src/toasty.service.ts",

0 commit comments

Comments
 (0)
0