Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ You could also pass the template through the `open()` method:
}
```

You can pass arbitrary data to your template:
```html
<ng-template #example let-text="text">
<p>{{ text }}!</p>
</ng-template>
```
```ts
@ViewChild('example') example: TemplateRef<any>;

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
Expand Down
21 changes: 15 additions & 6 deletions src/components/notification/notification.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,39 @@
<div *ngIf="!item.html">

<div class="sn-title" *ngIf="titleIsTemplate else regularTitle">
<ng-container *ngTemplateOutlet="title"></ng-container>
<ng-template [ngTemplateOutlet]="item.title"
[ngTemplateOutletContext]="templateData"
>
</ng-template>
</div>

<ng-template #regularTitle>
<div class="sn-title" [innerHTML]="title"></div>
<div class="sn-title" [innerHTML]="item.title"></div>
</ng-template>

<div class="sn-content" *ngIf="contentIsTemplate else regularContent">
<ng-container *ngTemplateOutlet="content"></ng-container>
<ng-template [ngTemplateOutlet]="item.content"
[ngTemplateOutletContext]="templateData"
>
</ng-template>
</div>

<ng-template #regularContent>
<div class="sn-content" [innerHTML]="content"></div>
<div class="sn-content" [innerHTML]="item.content"></div>
</ng-template>

<div class="icon" *ngIf="item.icon !== 'bare'" [innerHTML]="safeSvg"></div>
</div>
<div *ngIf="item.html">
<div class="sn-html" *ngIf="htmlIsTemplate else regularHtml">
<ng-container *ngTemplateOutlet="item.html"></ng-container>
<ng-template [ngTemplateOutlet]="item.html"
[ngTemplateOutletContext]="templateData"
>
</ng-template>
</div>

<ng-template #regularHtml>
<div class="sn-content" [innerHTML]="item.html"></div>
<div class="sn-html" [innerHTML]="item.html"></div>
</ng-template>

<div class="icon" [class.icon-hover]="clickIconToClose" *ngIf="item.icon" [innerHTML]="safeSvg" (click)="onClickIcon($event)"></div>
Expand Down
9 changes: 1 addition & 8 deletions src/components/notification/notification.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}