MCPcopy Index your code
hub / github.com/angular/components / createOverlayRef

Function createOverlayRef

src/cdk/overlay/overlay.ts:52–116  ·  view source on GitHub ↗
(injector: Injector, config?: OverlayConfig)

Source from the content-addressed store, hash-verified

50 * @returns Reference to the created overlay.
51 */
52export function createOverlayRef(injector: Injector, config?: OverlayConfig): OverlayRef {
53 // This is done in the overlay container as well, but we have it here
54 // since it's common to mock out the overlay container in tests.
55 injector.get(_CdkPrivateStyleLoader).load(_CdkOverlayStyleLoader);
56
57 const overlayContainer = injector.get(OverlayContainer);
58 const doc = injector.get(DOCUMENT);
59 const idGenerator = injector.get(_IdGenerator);
60 const appRef = injector.get(ApplicationRef);
61 const directionality = injector.get(Directionality);
62 const renderer =
63 injector.get(Renderer2, null, {optional: true}) ||
64 injector.get(RendererFactory2).createRenderer(null, null);
65
66 const overlayConfig = new OverlayConfig(config);
67 const defaultUsePopover =
68 injector.get(OVERLAY_DEFAULT_CONFIG, null, {optional: true})?.usePopover ?? true;
69
70 overlayConfig.direction = overlayConfig.direction || directionality.value;
71
72 if (!('showPopover' in doc.body)) {
73 overlayConfig.usePopover = false;
74 } else {
75 overlayConfig.usePopover = config?.usePopover ?? defaultUsePopover;
76 }
77
78 const pane = doc.createElement('div');
79 const host = doc.createElement('div');
80 pane.id = idGenerator.getId('cdk-overlay-');
81 pane.classList.add('cdk-overlay-pane');
82 host.appendChild(pane);
83
84 if (overlayConfig.usePopover) {
85 host.setAttribute('popover', 'manual');
86 host.classList.add('cdk-overlay-popover');
87 }
88
89 const customInsertionPoint = overlayConfig.usePopover
90 ? overlayConfig.positionStrategy?.getPopoverInsertionPoint?.()
91 : null;
92
93 if (isElement(customInsertionPoint)) {
94 customInsertionPoint.after(host);
95 } else if (customInsertionPoint?.type === 'parent') {
96 customInsertionPoint.element.appendChild(host);
97 } else {
98 overlayContainer.getContainerElement().appendChild(host);
99 }
100
101 return new OverlayRef(
102 new DomPortalOutlet(pane, appRef, injector),
103 host,
104 pane,
105 overlayConfig,
106 injector.get(NgZone),
107 injector.get(OverlayKeyboardDispatcher),
108 doc,
109 injector.get(Location),

Callers 15

openWithConfigMethod · 0.90
_createOverlayForHandleFunction · 0.90
_createEditOverlayMethod · 0.90
_createOverlayMethod · 0.90
_getOverlayRefMethod · 0.90
_createOverlayFunction · 0.90
_attachOverlayMethod · 0.90
_createOverlayMethod · 0.90
_openOverlayFunction · 0.90
_openMethod · 0.90
openMethod · 0.90

Calls 7

isElementFunction · 0.90
loadMethod · 0.80
getContainerElementMethod · 0.80
getMethod · 0.65
getIdMethod · 0.45
addMethod · 0.45

Tested by 2

attachOverlayFunction · 0.68
attachOverlayFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…