fix(angular): fix overlays

This commit is contained in:
Manu Mtz.-Almeida
2018-03-13 19:21:26 +01:00
parent de22ecae82
commit cc4fecc1be
12 changed files with 167 additions and 759 deletions

View File

@ -0,0 +1,15 @@
import { proxyMethod } from '../util/util';
export class OverlayBaseController<Opts, Overlay> {
constructor(private ctrl: string) {}
create(opts?: Opts): Promise<Overlay> {
return proxyMethod(this.ctrl, 'create', opts);
}
dismiss(data?: any, role?: string, id = -1): Promise<void> {
return proxyMethod(this.ctrl, 'dismiss', data, role, id);
}
}

View File

@ -1,19 +1,19 @@
export function hydrateElement(element: any) {
return element.componentOnReady();
}
export function getElement(elementName: string) {
return document.querySelector(elementName);
export function proxyMethod(ctrlName: string, methodName: string, ...args: any[]) {
const controller = ensureElementInBody(ctrlName);
return controller.componentOnReady()
.then(() => (controller as any)[methodName].apply(args));
}
export function ensureElementInBody(elementName: string) {
let element = getElement(elementName);
let element = document.querySelector(elementName);
if (!element) {
element = document.createElement(elementName);
document.body.appendChild(element);
}
return element;
return element as HTMLStencilElement;
}
export function removeAllNodeChildren(element: HTMLElement) {