angular2-toaster-mod
Version:
An Angular 2 Toaster Notification library based on AngularJS-Toaster
51 lines • 3.01 kB
JavaScript
import { Component, Input, ViewChild, ViewContainerRef, EventEmitter, ComponentFactoryResolver, ChangeDetectorRef } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { BodyOutputType } from './bodyOutputType';
export var ToastComponent = (function () {
function ToastComponent(sanitizer, componentFactoryResolver, changeDetectorRef) {
this.sanitizer = sanitizer;
this.componentFactoryResolver = componentFactoryResolver;
this.changeDetectorRef = changeDetectorRef;
this.bodyOutputType = BodyOutputType;
this.clickEvent = new EventEmitter();
}
ToastComponent.prototype.ngOnInit = function () {
if (this.toast.closeHtml) {
this.safeCloseHtml = this.sanitizer.bypassSecurityTrustHtml(this.toast.closeHtml);
}
};
ToastComponent.prototype.ngAfterViewInit = function () {
if (this.toast.bodyOutputType === this.bodyOutputType.Component) {
var component = this.componentFactoryResolver.resolveComponentFactory(this.toast.body);
var componentInstance = this.componentBody.createComponent(component, null, this.componentBody.injector);
componentInstance.instance.toast = this.toast;
this.changeDetectorRef.detectChanges();
}
};
ToastComponent.prototype.click = function (event, toast) {
event.stopPropagation();
this.clickEvent.emit({
value: { toast: toast, isCloseButton: true }
});
};
ToastComponent.decorators = [
{ type: Component, args: [{
selector: '[toastComp]',
template: "\n <i class=\"toaster-icon\" [ngClass]=\"iconClass\"></i>\n <div class=\"toast-content\">\n <div [ngClass]=\"toast.toasterConfig.titleClass\">{{toast.title}}</div>\n <div [ngClass]=\"toast.toasterConfig.messageClass\" [ngSwitch]=\"toast.bodyOutputType\">\n <div *ngSwitchCase=\"bodyOutputType.Component\" #componentBody></div>\n <div *ngSwitchCase=\"bodyOutputType.TrustedHtml\" [innerHTML]=\"toast.body\"></div>\n <div *ngSwitchCase=\"bodyOutputType.Default\">{{toast.body}}</div>\n </div>\n </div>\n <div class=\"toast-close-button\" *ngIf=\"toast.showCloseButton\" (click)=\"click($event, toast)\"\n [innerHTML]=\"safeCloseHtml\">\n </div>",
outputs: ['clickEvent']
},] },
];
/** @nocollapse */
ToastComponent.ctorParameters = function () { return [
{ type: DomSanitizer, },
{ type: ComponentFactoryResolver, },
{ type: ChangeDetectorRef, },
]; };
ToastComponent.propDecorators = {
'toast': [{ type: Input },],
'iconClass': [{ type: Input },],
'componentBody': [{ type: ViewChild, args: ['componentBody', { read: ViewContainerRef },] },],
};
return ToastComponent;
}());
//# sourceMappingURL=toast.component.js.map