45 lines
5.2 KiB
JavaScript
45 lines
5.2 KiB
JavaScript
|
import { DOCUMENT } from '@angular/common';
|
||
|
import { inject, Injectable } from '@angular/core';
|
||
|
import * as i0 from "@angular/core";
|
||
|
/** Container inside which all toasts will render. */
|
||
|
class OverlayContainer {
|
||
|
_document = inject(DOCUMENT);
|
||
|
_containerElement;
|
||
|
ngOnDestroy() {
|
||
|
if (this._containerElement && this._containerElement.parentNode) {
|
||
|
this._containerElement.parentNode.removeChild(this._containerElement);
|
||
|
}
|
||
|
}
|
||
|
/**
|
||
|
* This method returns the overlay container element. It will lazily
|
||
|
* create the element the first time it is called to facilitate using
|
||
|
* the container in non-browser environments.
|
||
|
* @returns the container element
|
||
|
*/
|
||
|
getContainerElement() {
|
||
|
if (!this._containerElement) {
|
||
|
this._createContainer();
|
||
|
}
|
||
|
return this._containerElement;
|
||
|
}
|
||
|
/**
|
||
|
* Create the overlay container element, which is simply a div
|
||
|
* with the 'cdk-overlay-container' class on the document body
|
||
|
* and 'aria-live="polite"'
|
||
|
*/
|
||
|
_createContainer() {
|
||
|
const container = this._document.createElement('div');
|
||
|
container.classList.add('overlay-container');
|
||
|
container.setAttribute('aria-live', 'polite');
|
||
|
this._document.body.appendChild(container);
|
||
|
this._containerElement = container;
|
||
|
}
|
||
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: OverlayContainer, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
||
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: OverlayContainer, providedIn: 'root' });
|
||
|
}
|
||
|
export { OverlayContainer };
|
||
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: OverlayContainer, decorators: [{
|
||
|
type: Injectable,
|
||
|
args: [{ providedIn: 'root' }]
|
||
|
}] });
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj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