From 8c18247a2f6b0214c10bb3d66b325563b620d0cc Mon Sep 17 00:00:00 2001 From: "sergey.sokolov" Date: Tue, 14 Nov 2017 13:31:00 +0300 Subject: [PATCH] Added a way to pass arbitrary data to templates. Removed bypassSecurityTrustHtml for user-provided templates, its totally unsafe to use it. Fixed class for html inserted via innerHTML (from sn-content to sn-html) --- README.md | 17 +++++++++++++++ .../notification/notification.component.html | 21 +++++++++++++------ .../notification/notification.component.ts | 9 +------- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c22ff68..bbf7089 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,23 @@ You could also pass the template through the `open()` method: } ``` +You can pass arbitrary data to your template: +```html + +

{{ text }}!

+
+``` +```ts + @ViewChild('example') example: TemplateRef; + + open() { + this._service.success(this.example, null, { + templateData: {text: 'hi'}, + }); + } +``` + + ## Subscribing to clicks If you are interested in the clicks that happen on a notification you have the possibility to subscribe to a EventEmitter. The methods (success, error, alert, warn, info, warn, bare, create and html) from the diff --git a/src/components/notification/notification.component.html b/src/components/notification/notification.component.html index 641c644..1260287 100644 --- a/src/components/notification/notification.component.html +++ b/src/components/notification/notification.component.html @@ -17,30 +17,39 @@
- + +
-
+
- + +
-
+
- + +
-
+
diff --git a/src/components/notification/notification.component.ts b/src/components/notification/notification.component.ts index adc0df7..eb9d29a 100644 --- a/src/components/notification/notification.component.ts +++ b/src/components/notification/notification.component.ts @@ -126,9 +126,8 @@ export class NotificationComponent implements OnInit, OnDestroy { // Progress bar variables - public title: any; - public content: any; + public templateData: any = null; public titleIsTemplate = false; public contentIsTemplate = false; public htmlIsTemplate = false; @@ -250,12 +249,6 @@ export class NotificationComponent implements OnInit, OnDestroy { } private contentType(item: any, key: string) { - if (item instanceof TemplateRef) { - this[key] = item; - } else { - this[key] = this.domSanitizer.bypassSecurityTrustHtml(item); - } - this[key + 'IsTemplate'] = item instanceof TemplateRef; } }