99 OnDestroy
1010} from "@angular/core" ;
1111
12- import { Banner } from "./banner.component" ;
1312import { BannerContent , NotificationContent , ToastContent } from "./banner-content.interface" ;
13+ import { Banner , Toast } from "./banner.module" ;
1414
1515/**
1616 * Provides a way to use the banner component.
@@ -31,15 +31,6 @@ export class BannerService implements OnDestroy {
3131 public bannerRefs = new Array < ComponentRef < any > > ( ) ;
3232 public onClose : EventEmitter < any > = new EventEmitter ( ) ;
3333
34- /**
35- * Used to create banners.
36- *
37- * @private
38- * @type {ComponentFactory<any> }
39- * @memberof BannerService
40- */
41- private componentFactory : ComponentFactory < any > ;
42-
4334 /**
4435 * Constructs BannerService.
4536 *
@@ -82,18 +73,14 @@ export class BannerService implements OnDestroy {
8273 * }
8374 * ```
8475 *
85- * @param {any } [bannerComp=null ] If provided, used to resolve component factory
76+ * @param {any } [bannerComp=Banner ] If provided, used to resolve component factory
8677 * @memberof BannerService
8778 */
88- showBanner ( bannerObj : BannerContent | NotificationContent | ToastContent , bannerComp = null ) : Banner {
89- if ( ! bannerComp ) {
90- this . componentFactory = this . componentFactoryResolver . resolveComponentFactory ( Banner ) ;
91- } else {
92- this . componentFactory = this . componentFactoryResolver . resolveComponentFactory ( bannerComp ) ;
93- }
79+ showBanner ( bannerObj : BannerContent | NotificationContent | ToastContent , bannerComp = Banner ) {
80+ const componentFactory = this . componentFactoryResolver . resolveComponentFactory ( bannerComp ) ;
9481
95- let bannerRef = this . componentFactory . create ( this . injector ) ;
96- bannerRef . instance . bannerObj = bannerObj ;
82+ let bannerRef = componentFactory . create ( this . injector ) ;
83+ bannerRef . instance . bannerObj = bannerObj as any ; // typescript isn't being very smart here, so we type to any
9784 this . bannerRefs . push ( bannerRef ) ;
9885
9986 this . onClose = bannerRef . instance . close ;
@@ -106,7 +93,7 @@ export class BannerService implements OnDestroy {
10693
10794 // get or create a container for alert list
10895 let bannerClassName = "banner-overlay" ;
109- let bannerList = body . querySelector ( "." + bannerClassName ) ;
96+ let bannerList = body . querySelector ( `. ${ bannerClassName } ` ) ;
11097 if ( ! bannerList ) {
11198 bannerList = document . createElement ( "div" ) ;
11299 bannerList . className = bannerClassName ;
@@ -142,6 +129,10 @@ export class BannerService implements OnDestroy {
142129 return bannerRef . instance ;
143130 }
144131
132+ showToast ( bannerObj : BannerContent | NotificationContent | ToastContent , bannerComp = Toast ) {
133+ return this . showBanner ( bannerObj , bannerComp ) ;
134+ }
135+
145136 /**
146137 * Programatically closes banner based on `bannerRef`.
147138 *
0 commit comments