MCPcopy Index your code
hub / github.com/ionic-team/ionic-framework / attachComponent

Function attachComponent

core/src/utils/framework-delegate.ts:7–36  ·  view source on GitHub ↗
(
  delegate: FrameworkDelegate | undefined,
  container: Element,
  component?: ComponentRef,
  cssClasses?: string[],
  componentProps?: { [key: string]: any },
  inline?: boolean
)

Source from the content-addressed store, hash-verified

5// TODO(FW-2832): types
6
7export const attachComponent = async (
8 delegate: FrameworkDelegate | undefined,
9 container: Element,
10 component?: ComponentRef,
11 cssClasses?: string[],
12 componentProps?: { [key: string]: any },
13 inline?: boolean
14): Promise<HTMLElement> => {
15 if (delegate) {
16 return delegate.attachViewToDom(container, component, componentProps, cssClasses);
17 }
18 if (!inline && typeof component !== 'string' && !(component instanceof HTMLElement)) {
19 throw new Error('framework delegate is missing');
20 }
21
22 const el: any = typeof component === 'string' ? container.ownerDocument?.createElement(component) : component;
23
24 if (cssClasses) {
25 cssClasses.forEach((c) => el.classList.add(c));
26 }
27 if (componentProps) {
28 Object.assign(el, componentProps);
29 }
30
31 container.appendChild(el);
32
33 await new Promise((resolve) => componentOnReady(el, resolve));
34
35 return el;
36};
37
38export const detachComponent = (delegate: FrameworkDelegate | undefined, element: HTMLElement | undefined) => {
39 if (element) {

Callers 5

setRootMethod · 0.90
prepareLazyLoadedMethod · 0.90
initMethod · 0.90
presentMethod · 0.90
presentMethod · 0.90

Calls 3

componentOnReadyFunction · 0.90
attachViewToDomMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected