Created
January 30, 2017 19:14
-
-
Save venkateshwarv/7e8220f25077fb3d759f7a3d5597af7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { MdSnackBar, MdSnackBarRef, MdSnackBarContainer, Overlay, LiveAnnouncer, ComponentPortal, ComponentRef, OverlayRef, OverlayState } from '@angular/material'; | |
import { SnackbarContainerComponent } from './snackbar-container/snackbar-container.component'; | |
import { SnackbarComponent} from './snackbar/snackbar.component'; | |
@Injectable() | |
export class CcSnackBarService extends MdSnackBar { | |
constructor(private _overlay : Overlay, private liveAnnouncer : LiveAnnouncer, private mdSnackBar : MdSnackBar) { | |
super( | |
_overlay, liveAnnouncer, mdSnackBar | |
) | |
} | |
private _createOverlay(): OverlayRef { | |
let state = new OverlayState(); | |
state.positionStrategy = this._overlay.position().global() | |
.centerHorizontally() | |
.top('0'); | |
return this._overlay.create(state); | |
} | |
private _attachSnackBarContainer(overlayRef: OverlayRef, | |
config: MdSnackBarConfig) { | |
let containerPortal = new ComponentPortal(SnackbarContainerComponent, config.viewContainerRef); | |
let containerRef: ComponentRef<MdSnackBarContainer> = overlayRef.attach(containerPortal); | |
containerRef.instance.snackBarConfig = config; | |
console.log(containerRef.instance); | |
return containerRef.instance; | |
} | |
/** | |
* Places a new component as the content of the snack bar container. | |
*/ | |
private _attachSnackbarContent<T>(component: ComponentType<T>, | |
container: MdSnackBarContainer, | |
overlayRef: OverlayRef): MdSnackBarRef<T> { | |
let portal = new ComponentPortal(SnackbarComponent); | |
let contentRef = container.attachComponentPortal(portal); | |
return new MdSnackBarRef(contentRef.instance, container, overlayRef); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment