mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
16 lines
598 B
TypeScript
16 lines
598 B
TypeScript
// A proxy method that initializes the controller and calls requested method
|
|
export function proxyMethod(tag: string, method: string, ...opts: any[]): Promise<any> {
|
|
return initController(tag).then((ctrl: any) => ctrl[method].apply(ctrl, opts));
|
|
}
|
|
|
|
// Initialize an Ionic controller and append it to DOM
|
|
export function initController(tag: string): Promise<HTMLStencilElement> {
|
|
let element = document.querySelector(tag) as HTMLElement;
|
|
|
|
if (!element) {
|
|
element = document.body.appendChild(document.createElement(tag));
|
|
}
|
|
|
|
return (element as HTMLStencilElement).componentOnReady();
|
|
}
|