UNPKG

22.3 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { Injector, } from '@angular/core';
9import { BasePortalOutlet } from './portal';
10/**
11 * A PortalOutlet for attaching portals to an arbitrary DOM element outside of the Angular
12 * application context.
13 */
14export class DomPortalOutlet extends BasePortalOutlet {
15 /**
16 * @param outletElement Element into which the content is projected.
17 * @param _componentFactoryResolver Used to resolve the component factory.
18 * Only required when attaching component portals.
19 * @param _appRef Reference to the application. Only used in component portals when there
20 * is no `ViewContainerRef` available.
21 * @param _defaultInjector Injector to use as a fallback when the portal being attached doesn't
22 * have one. Only used for component portals.
23 * @param _document Reference to the document. Used when attaching a DOM portal. Will eventually
24 * become a required parameter.
25 */
26 constructor(
27 /** Element into which the content is projected. */
28 outletElement, _componentFactoryResolver, _appRef, _defaultInjector,
29 /**
30 * @deprecated `_document` Parameter to be made required.
31 * @breaking-change 10.0.0
32 */
33 _document) {
34 super();
35 this.outletElement = outletElement;
36 this._componentFactoryResolver = _componentFactoryResolver;
37 this._appRef = _appRef;
38 this._defaultInjector = _defaultInjector;
39 /**
40 * Attaches a DOM portal by transferring its content into the outlet.
41 * @param portal Portal to be attached.
42 * @deprecated To be turned into a method.
43 * @breaking-change 10.0.0
44 */
45 this.attachDomPortal = (portal) => {
46 // @breaking-change 10.0.0 Remove check and error once the
47 // `_document` constructor parameter is required.
48 if (!this._document && (typeof ngDevMode === 'undefined' || ngDevMode)) {
49 throw Error('Cannot attach DOM portal without _document constructor parameter');
50 }
51 const element = portal.element;
52 if (!element.parentNode && (typeof ngDevMode === 'undefined' || ngDevMode)) {
53 throw Error('DOM portal content must be attached to a parent node.');
54 }
55 // Anchor used to save the element's previous position so
56 // that we can restore it when the portal is detached.
57 const anchorNode = this._document.createComment('dom-portal');
58 element.parentNode.insertBefore(anchorNode, element);
59 this.outletElement.appendChild(element);
60 this._attachedPortal = portal;
61 super.setDisposeFn(() => {
62 // We can't use `replaceWith` here because IE doesn't support it.
63 if (anchorNode.parentNode) {
64 anchorNode.parentNode.replaceChild(element, anchorNode);
65 }
66 });
67 };
68 this._document = _document;
69 }
70 /**
71 * Attach the given ComponentPortal to DOM element using the ComponentFactoryResolver.
72 * @param portal Portal to be attached
73 * @returns Reference to the created component.
74 */
75 attachComponentPortal(portal) {
76 const resolver = (portal.componentFactoryResolver || this._componentFactoryResolver);
77 if ((typeof ngDevMode === 'undefined' || ngDevMode) && !resolver) {
78 throw Error('Cannot attach component portal to outlet without a ComponentFactoryResolver.');
79 }
80 const componentFactory = resolver.resolveComponentFactory(portal.component);
81 let componentRef;
82 // If the portal specifies a ViewContainerRef, we will use that as the attachment point
83 // for the component (in terms of Angular's component tree, not rendering).
84 // When the ViewContainerRef is missing, we use the factory to create the component directly
85 // and then manually attach the view to the application.
86 if (portal.viewContainerRef) {
87 componentRef = portal.viewContainerRef.createComponent(componentFactory, portal.viewContainerRef.length, portal.injector || portal.viewContainerRef.injector, portal.projectableNodes || undefined);
88 this.setDisposeFn(() => componentRef.destroy());
89 }
90 else {
91 if ((typeof ngDevMode === 'undefined' || ngDevMode) && !this._appRef) {
92 throw Error('Cannot attach component portal to outlet without an ApplicationRef.');
93 }
94 componentRef = componentFactory.create(portal.injector || this._defaultInjector || Injector.NULL);
95 this._appRef.attachView(componentRef.hostView);
96 this.setDisposeFn(() => {
97 // Verify that the ApplicationRef has registered views before trying to detach a host view.
98 // This check also protects the `detachView` from being called on a destroyed ApplicationRef.
99 if (this._appRef.viewCount > 0) {
100 this._appRef.detachView(componentRef.hostView);
101 }
102 componentRef.destroy();
103 });
104 }
105 // At this point the component has been instantiated, so we move it to the location in the DOM
106 // where we want it to be rendered.
107 this.outletElement.appendChild(this._getComponentRootNode(componentRef));
108 this._attachedPortal = portal;
109 return componentRef;
110 }
111 /**
112 * Attaches a template portal to the DOM as an embedded view.
113 * @param portal Portal to be attached.
114 * @returns Reference to the created embedded view.
115 */
116 attachTemplatePortal(portal) {
117 let viewContainer = portal.viewContainerRef;
118 let viewRef = viewContainer.createEmbeddedView(portal.templateRef, portal.context, {
119 injector: portal.injector,
120 });
121 // The method `createEmbeddedView` will add the view as a child of the viewContainer.
122 // But for the DomPortalOutlet the view can be added everywhere in the DOM
123 // (e.g Overlay Container) To move the view to the specified host element. We just
124 // re-append the existing root nodes.
125 viewRef.rootNodes.forEach(rootNode => this.outletElement.appendChild(rootNode));
126 // Note that we want to detect changes after the nodes have been moved so that
127 // any directives inside the portal that are looking at the DOM inside a lifecycle
128 // hook won't be invoked too early.
129 viewRef.detectChanges();
130 this.setDisposeFn(() => {
131 let index = viewContainer.indexOf(viewRef);
132 if (index !== -1) {
133 viewContainer.remove(index);
134 }
135 });
136 this._attachedPortal = portal;
137 // TODO(jelbourn): Return locals from view.
138 return viewRef;
139 }
140 /**
141 * Clears out a portal from the DOM.
142 */
143 dispose() {
144 super.dispose();
145 this.outletElement.remove();
146 }
147 /** Gets the root HTMLElement for an instantiated component. */
148 _getComponentRootNode(componentRef) {
149 return componentRef.hostView.rootNodes[0];
150 }
151}
152/**
153 * @deprecated Use `DomPortalOutlet` instead.
154 * @breaking-change 9.0.0
155 */
156export class DomPortalHost extends DomPortalOutlet {
157}
158//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZG9tLXBvcnRhbC1vdXRsZXQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL3BvcnRhbC9kb20tcG9ydGFsLW91dGxldC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBS0wsUUFBUSxHQUNULE1BQU0sZUFBZSxDQUFDO0FBQ3ZCLE9BQU8sRUFBQyxnQkFBZ0IsRUFBNkMsTUFBTSxVQUFVLENBQUM7QUFFdEY7OztHQUdHO0FBQ0g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