portal.es5.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  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. */
  8. import { __extends } from 'tslib';
  9. import { ComponentFactoryResolver, Directive, EventEmitter, NgModule, Output, TemplateRef, ViewContainerRef } from '@angular/core';
  10. /**
  11. * @fileoverview added by tsickle
  12. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  13. */
  14. /**
  15. * Throws an exception when attempting to attach a null portal to a host.
  16. * \@docs-private
  17. * @return {?}
  18. */
  19. function throwNullPortalError() {
  20. throw Error('Must provide a portal to attach');
  21. }
  22. /**
  23. * Throws an exception when attempting to attach a portal to a host that is already attached.
  24. * \@docs-private
  25. * @return {?}
  26. */
  27. function throwPortalAlreadyAttachedError() {
  28. throw Error('Host already has a portal attached');
  29. }
  30. /**
  31. * Throws an exception when attempting to attach a portal to an already-disposed host.
  32. * \@docs-private
  33. * @return {?}
  34. */
  35. function throwPortalOutletAlreadyDisposedError() {
  36. throw Error('This PortalOutlet has already been disposed');
  37. }
  38. /**
  39. * Throws an exception when attempting to attach an unknown portal type.
  40. * \@docs-private
  41. * @return {?}
  42. */
  43. function throwUnknownPortalTypeError() {
  44. throw Error('Attempting to attach an unknown Portal type. BasePortalOutlet accepts either ' +
  45. 'a ComponentPortal or a TemplatePortal.');
  46. }
  47. /**
  48. * Throws an exception when attempting to attach a portal to a null host.
  49. * \@docs-private
  50. * @return {?}
  51. */
  52. function throwNullPortalOutletError() {
  53. throw Error('Attempting to attach a portal to a null PortalOutlet');
  54. }
  55. /**
  56. * Throws an exception when attempting to detach a portal that is not attached.
  57. * \@docs-private
  58. * @return {?}
  59. */
  60. function throwNoPortalAttachedError() {
  61. throw Error('Attempting to detach a portal that is not attached to a host');
  62. }
  63. /**
  64. * @fileoverview added by tsickle
  65. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  66. */
  67. /**
  68. * A `Portal` is something that you want to render somewhere else.
  69. * It can be attach to / detached from a `PortalOutlet`.
  70. * @abstract
  71. * @template T
  72. */
  73. var /**
  74. * A `Portal` is something that you want to render somewhere else.
  75. * It can be attach to / detached from a `PortalOutlet`.
  76. * @abstract
  77. * @template T
  78. */
  79. Portal = /** @class */ (function () {
  80. function Portal() {
  81. }
  82. /** Attach this portal to a host. */
  83. /**
  84. * Attach this portal to a host.
  85. * @param {?} host
  86. * @return {?}
  87. */
  88. Portal.prototype.attach = /**
  89. * Attach this portal to a host.
  90. * @param {?} host
  91. * @return {?}
  92. */
  93. function (host) {
  94. if (host == null) {
  95. throwNullPortalOutletError();
  96. }
  97. if (host.hasAttached()) {
  98. throwPortalAlreadyAttachedError();
  99. }
  100. this._attachedHost = host;
  101. return (/** @type {?} */ (host.attach(this)));
  102. };
  103. /** Detach this portal from its host */
  104. /**
  105. * Detach this portal from its host
  106. * @return {?}
  107. */
  108. Portal.prototype.detach = /**
  109. * Detach this portal from its host
  110. * @return {?}
  111. */
  112. function () {
  113. /** @type {?} */
  114. var host = this._attachedHost;
  115. if (host == null) {
  116. throwNoPortalAttachedError();
  117. }
  118. else {
  119. this._attachedHost = null;
  120. host.detach();
  121. }
  122. };
  123. Object.defineProperty(Portal.prototype, "isAttached", {
  124. /** Whether this portal is attached to a host. */
  125. get: /**
  126. * Whether this portal is attached to a host.
  127. * @return {?}
  128. */
  129. function () {
  130. return this._attachedHost != null;
  131. },
  132. enumerable: true,
  133. configurable: true
  134. });
  135. /**
  136. * Sets the PortalOutlet reference without performing `attach()`. This is used directly by
  137. * the PortalOutlet when it is performing an `attach()` or `detach()`.
  138. */
  139. /**
  140. * Sets the PortalOutlet reference without performing `attach()`. This is used directly by
  141. * the PortalOutlet when it is performing an `attach()` or `detach()`.
  142. * @param {?} host
  143. * @return {?}
  144. */
  145. Portal.prototype.setAttachedHost = /**
  146. * Sets the PortalOutlet reference without performing `attach()`. This is used directly by
  147. * the PortalOutlet when it is performing an `attach()` or `detach()`.
  148. * @param {?} host
  149. * @return {?}
  150. */
  151. function (host) {
  152. this._attachedHost = host;
  153. };
  154. return Portal;
  155. }());
  156. /**
  157. * A `ComponentPortal` is a portal that instantiates some Component upon attachment.
  158. * @template T
  159. */
  160. var /**
  161. * A `ComponentPortal` is a portal that instantiates some Component upon attachment.
  162. * @template T
  163. */
  164. ComponentPortal = /** @class */ (function (_super) {
  165. __extends(ComponentPortal, _super);
  166. function ComponentPortal(component, viewContainerRef, injector, componentFactoryResolver) {
  167. var _this = _super.call(this) || this;
  168. _this.component = component;
  169. _this.viewContainerRef = viewContainerRef;
  170. _this.injector = injector;
  171. _this.componentFactoryResolver = componentFactoryResolver;
  172. return _this;
  173. }
  174. return ComponentPortal;
  175. }(Portal));
  176. /**
  177. * A `TemplatePortal` is a portal that represents some embedded template (TemplateRef).
  178. * @template C
  179. */
  180. var /**
  181. * A `TemplatePortal` is a portal that represents some embedded template (TemplateRef).
  182. * @template C
  183. */
  184. TemplatePortal = /** @class */ (function (_super) {
  185. __extends(TemplatePortal, _super);
  186. function TemplatePortal(template, viewContainerRef, context) {
  187. var _this = _super.call(this) || this;
  188. _this.templateRef = template;
  189. _this.viewContainerRef = viewContainerRef;
  190. _this.context = context;
  191. return _this;
  192. }
  193. Object.defineProperty(TemplatePortal.prototype, "origin", {
  194. get: /**
  195. * @return {?}
  196. */
  197. function () {
  198. return this.templateRef.elementRef;
  199. },
  200. enumerable: true,
  201. configurable: true
  202. });
  203. /**
  204. * Attach the portal to the provided `PortalOutlet`.
  205. * When a context is provided it will override the `context` property of the `TemplatePortal`
  206. * instance.
  207. */
  208. /**
  209. * Attach the portal to the provided `PortalOutlet`.
  210. * When a context is provided it will override the `context` property of the `TemplatePortal`
  211. * instance.
  212. * @param {?} host
  213. * @param {?=} context
  214. * @return {?}
  215. */
  216. TemplatePortal.prototype.attach = /**
  217. * Attach the portal to the provided `PortalOutlet`.
  218. * When a context is provided it will override the `context` property of the `TemplatePortal`
  219. * instance.
  220. * @param {?} host
  221. * @param {?=} context
  222. * @return {?}
  223. */
  224. function (host, context) {
  225. if (context === void 0) { context = this.context; }
  226. this.context = context;
  227. return _super.prototype.attach.call(this, host);
  228. };
  229. /**
  230. * @return {?}
  231. */
  232. TemplatePortal.prototype.detach = /**
  233. * @return {?}
  234. */
  235. function () {
  236. this.context = undefined;
  237. return _super.prototype.detach.call(this);
  238. };
  239. return TemplatePortal;
  240. }(Portal));
  241. /**
  242. * Partial implementation of PortalOutlet that handles attaching
  243. * ComponentPortal and TemplatePortal.
  244. * @abstract
  245. */
  246. var /**
  247. * Partial implementation of PortalOutlet that handles attaching
  248. * ComponentPortal and TemplatePortal.
  249. * @abstract
  250. */
  251. BasePortalOutlet = /** @class */ (function () {
  252. function BasePortalOutlet() {
  253. /**
  254. * Whether this host has already been permanently disposed.
  255. */
  256. this._isDisposed = false;
  257. }
  258. /** Whether this host has an attached portal. */
  259. /**
  260. * Whether this host has an attached portal.
  261. * @return {?}
  262. */
  263. BasePortalOutlet.prototype.hasAttached = /**
  264. * Whether this host has an attached portal.
  265. * @return {?}
  266. */
  267. function () {
  268. return !!this._attachedPortal;
  269. };
  270. /** Attaches a portal. */
  271. /**
  272. * Attaches a portal.
  273. * @param {?} portal
  274. * @return {?}
  275. */
  276. BasePortalOutlet.prototype.attach = /**
  277. * Attaches a portal.
  278. * @param {?} portal
  279. * @return {?}
  280. */
  281. function (portal) {
  282. if (!portal) {
  283. throwNullPortalError();
  284. }
  285. if (this.hasAttached()) {
  286. throwPortalAlreadyAttachedError();
  287. }
  288. if (this._isDisposed) {
  289. throwPortalOutletAlreadyDisposedError();
  290. }
  291. if (portal instanceof ComponentPortal) {
  292. this._attachedPortal = portal;
  293. return this.attachComponentPortal(portal);
  294. }
  295. else if (portal instanceof TemplatePortal) {
  296. this._attachedPortal = portal;
  297. return this.attachTemplatePortal(portal);
  298. }
  299. throwUnknownPortalTypeError();
  300. };
  301. /** Detaches a previously attached portal. */
  302. /**
  303. * Detaches a previously attached portal.
  304. * @return {?}
  305. */
  306. BasePortalOutlet.prototype.detach = /**
  307. * Detaches a previously attached portal.
  308. * @return {?}
  309. */
  310. function () {
  311. if (this._attachedPortal) {
  312. this._attachedPortal.setAttachedHost(null);
  313. this._attachedPortal = null;
  314. }
  315. this._invokeDisposeFn();
  316. };
  317. /** Permanently dispose of this portal host. */
  318. /**
  319. * Permanently dispose of this portal host.
  320. * @return {?}
  321. */
  322. BasePortalOutlet.prototype.dispose = /**
  323. * Permanently dispose of this portal host.
  324. * @return {?}
  325. */
  326. function () {
  327. if (this.hasAttached()) {
  328. this.detach();
  329. }
  330. this._invokeDisposeFn();
  331. this._isDisposed = true;
  332. };
  333. /** @docs-private */
  334. /**
  335. * \@docs-private
  336. * @param {?} fn
  337. * @return {?}
  338. */
  339. BasePortalOutlet.prototype.setDisposeFn = /**
  340. * \@docs-private
  341. * @param {?} fn
  342. * @return {?}
  343. */
  344. function (fn) {
  345. this._disposeFn = fn;
  346. };
  347. /**
  348. * @private
  349. * @return {?}
  350. */
  351. BasePortalOutlet.prototype._invokeDisposeFn = /**
  352. * @private
  353. * @return {?}
  354. */
  355. function () {
  356. if (this._disposeFn) {
  357. this._disposeFn();
  358. this._disposeFn = null;
  359. }
  360. };
  361. return BasePortalOutlet;
  362. }());
  363. /**
  364. * @deprecated Use `BasePortalOutlet` instead.
  365. * \@breaking-change 9.0.0
  366. * @abstract
  367. */
  368. var /**
  369. * @deprecated Use `BasePortalOutlet` instead.
  370. * \@breaking-change 9.0.0
  371. * @abstract
  372. */
  373. BasePortalHost = /** @class */ (function (_super) {
  374. __extends(BasePortalHost, _super);
  375. function BasePortalHost() {
  376. return _super !== null && _super.apply(this, arguments) || this;
  377. }
  378. return BasePortalHost;
  379. }(BasePortalOutlet));
  380. /**
  381. * @fileoverview added by tsickle
  382. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  383. */
  384. /**
  385. * A PortalOutlet for attaching portals to an arbitrary DOM element outside of the Angular
  386. * application context.
  387. */
  388. var /**
  389. * A PortalOutlet for attaching portals to an arbitrary DOM element outside of the Angular
  390. * application context.
  391. */
  392. DomPortalOutlet = /** @class */ (function (_super) {
  393. __extends(DomPortalOutlet, _super);
  394. function DomPortalOutlet(outletElement, _componentFactoryResolver, _appRef, _defaultInjector) {
  395. var _this = _super.call(this) || this;
  396. _this.outletElement = outletElement;
  397. _this._componentFactoryResolver = _componentFactoryResolver;
  398. _this._appRef = _appRef;
  399. _this._defaultInjector = _defaultInjector;
  400. return _this;
  401. }
  402. /**
  403. * Attach the given ComponentPortal to DOM element using the ComponentFactoryResolver.
  404. * @param portal Portal to be attached
  405. * @returns Reference to the created component.
  406. */
  407. /**
  408. * Attach the given ComponentPortal to DOM element using the ComponentFactoryResolver.
  409. * @template T
  410. * @param {?} portal Portal to be attached
  411. * @return {?} Reference to the created component.
  412. */
  413. DomPortalOutlet.prototype.attachComponentPortal = /**
  414. * Attach the given ComponentPortal to DOM element using the ComponentFactoryResolver.
  415. * @template T
  416. * @param {?} portal Portal to be attached
  417. * @return {?} Reference to the created component.
  418. */
  419. function (portal) {
  420. var _this = this;
  421. /** @type {?} */
  422. var resolver = portal.componentFactoryResolver || this._componentFactoryResolver;
  423. /** @type {?} */
  424. var componentFactory = resolver.resolveComponentFactory(portal.component);
  425. /** @type {?} */
  426. var componentRef;
  427. // If the portal specifies a ViewContainerRef, we will use that as the attachment point
  428. // for the component (in terms of Angular's component tree, not rendering).
  429. // When the ViewContainerRef is missing, we use the factory to create the component directly
  430. // and then manually attach the view to the application.
  431. if (portal.viewContainerRef) {
  432. componentRef = portal.viewContainerRef.createComponent(componentFactory, portal.viewContainerRef.length, portal.injector || portal.viewContainerRef.injector);
  433. this.setDisposeFn((/**
  434. * @return {?}
  435. */
  436. function () { return componentRef.destroy(); }));
  437. }
  438. else {
  439. componentRef = componentFactory.create(portal.injector || this._defaultInjector);
  440. this._appRef.attachView(componentRef.hostView);
  441. this.setDisposeFn((/**
  442. * @return {?}
  443. */
  444. function () {
  445. _this._appRef.detachView(componentRef.hostView);
  446. componentRef.destroy();
  447. }));
  448. }
  449. // At this point the component has been instantiated, so we move it to the location in the DOM
  450. // where we want it to be rendered.
  451. this.outletElement.appendChild(this._getComponentRootNode(componentRef));
  452. return componentRef;
  453. };
  454. /**
  455. * Attaches a template portal to the DOM as an embedded view.
  456. * @param portal Portal to be attached.
  457. * @returns Reference to the created embedded view.
  458. */
  459. /**
  460. * Attaches a template portal to the DOM as an embedded view.
  461. * @template C
  462. * @param {?} portal Portal to be attached.
  463. * @return {?} Reference to the created embedded view.
  464. */
  465. DomPortalOutlet.prototype.attachTemplatePortal = /**
  466. * Attaches a template portal to the DOM as an embedded view.
  467. * @template C
  468. * @param {?} portal Portal to be attached.
  469. * @return {?} Reference to the created embedded view.
  470. */
  471. function (portal) {
  472. var _this = this;
  473. /** @type {?} */
  474. var viewContainer = portal.viewContainerRef;
  475. /** @type {?} */
  476. var viewRef = viewContainer.createEmbeddedView(portal.templateRef, portal.context);
  477. viewRef.detectChanges();
  478. // The method `createEmbeddedView` will add the view as a child of the viewContainer.
  479. // But for the DomPortalOutlet the view can be added everywhere in the DOM
  480. // (e.g Overlay Container) To move the view to the specified host element. We just
  481. // re-append the existing root nodes.
  482. viewRef.rootNodes.forEach((/**
  483. * @param {?} rootNode
  484. * @return {?}
  485. */
  486. function (rootNode) { return _this.outletElement.appendChild(rootNode); }));
  487. this.setDisposeFn(((/**
  488. * @return {?}
  489. */
  490. function () {
  491. /** @type {?} */
  492. var index = viewContainer.indexOf(viewRef);
  493. if (index !== -1) {
  494. viewContainer.remove(index);
  495. }
  496. })));
  497. // TODO(jelbourn): Return locals from view.
  498. return viewRef;
  499. };
  500. /**
  501. * Clears out a portal from the DOM.
  502. */
  503. /**
  504. * Clears out a portal from the DOM.
  505. * @return {?}
  506. */
  507. DomPortalOutlet.prototype.dispose = /**
  508. * Clears out a portal from the DOM.
  509. * @return {?}
  510. */
  511. function () {
  512. _super.prototype.dispose.call(this);
  513. if (this.outletElement.parentNode != null) {
  514. this.outletElement.parentNode.removeChild(this.outletElement);
  515. }
  516. };
  517. /** Gets the root HTMLElement for an instantiated component. */
  518. /**
  519. * Gets the root HTMLElement for an instantiated component.
  520. * @private
  521. * @param {?} componentRef
  522. * @return {?}
  523. */
  524. DomPortalOutlet.prototype._getComponentRootNode = /**
  525. * Gets the root HTMLElement for an instantiated component.
  526. * @private
  527. * @param {?} componentRef
  528. * @return {?}
  529. */
  530. function (componentRef) {
  531. return (/** @type {?} */ (((/** @type {?} */ (componentRef.hostView))).rootNodes[0]));
  532. };
  533. return DomPortalOutlet;
  534. }(BasePortalOutlet));
  535. /**
  536. * @deprecated Use `DomPortalOutlet` instead.
  537. * \@breaking-change 9.0.0
  538. */
  539. var /**
  540. * @deprecated Use `DomPortalOutlet` instead.
  541. * \@breaking-change 9.0.0
  542. */
  543. DomPortalHost = /** @class */ (function (_super) {
  544. __extends(DomPortalHost, _super);
  545. function DomPortalHost() {
  546. return _super !== null && _super.apply(this, arguments) || this;
  547. }
  548. return DomPortalHost;
  549. }(DomPortalOutlet));
  550. /**
  551. * @fileoverview added by tsickle
  552. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  553. */
  554. /**
  555. * Directive version of a `TemplatePortal`. Because the directive *is* a TemplatePortal,
  556. * the directive instance itself can be attached to a host, enabling declarative use of portals.
  557. */
  558. var CdkPortal = /** @class */ (function (_super) {
  559. __extends(CdkPortal, _super);
  560. function CdkPortal(templateRef, viewContainerRef) {
  561. return _super.call(this, templateRef, viewContainerRef) || this;
  562. }
  563. CdkPortal.decorators = [
  564. { type: Directive, args: [{
  565. selector: '[cdkPortal]',
  566. exportAs: 'cdkPortal',
  567. },] },
  568. ];
  569. /** @nocollapse */
  570. CdkPortal.ctorParameters = function () { return [
  571. { type: TemplateRef },
  572. { type: ViewContainerRef }
  573. ]; };
  574. return CdkPortal;
  575. }(TemplatePortal));
  576. /**
  577. * @deprecated Use `CdkPortal` instead.
  578. * \@breaking-change 9.0.0
  579. */
  580. var TemplatePortalDirective = /** @class */ (function (_super) {
  581. __extends(TemplatePortalDirective, _super);
  582. function TemplatePortalDirective() {
  583. return _super !== null && _super.apply(this, arguments) || this;
  584. }
  585. TemplatePortalDirective.decorators = [
  586. { type: Directive, args: [{
  587. selector: '[cdk-portal], [portal]',
  588. exportAs: 'cdkPortal',
  589. providers: [{
  590. provide: CdkPortal,
  591. useExisting: TemplatePortalDirective
  592. }]
  593. },] },
  594. ];
  595. return TemplatePortalDirective;
  596. }(CdkPortal));
  597. /**
  598. * Directive version of a PortalOutlet. Because the directive *is* a PortalOutlet, portals can be
  599. * directly attached to it, enabling declarative use.
  600. *
  601. * Usage:
  602. * `<ng-template [cdkPortalOutlet]="greeting"></ng-template>`
  603. */
  604. var CdkPortalOutlet = /** @class */ (function (_super) {
  605. __extends(CdkPortalOutlet, _super);
  606. function CdkPortalOutlet(_componentFactoryResolver, _viewContainerRef) {
  607. var _this = _super.call(this) || this;
  608. _this._componentFactoryResolver = _componentFactoryResolver;
  609. _this._viewContainerRef = _viewContainerRef;
  610. /**
  611. * Whether the portal component is initialized.
  612. */
  613. _this._isInitialized = false;
  614. /**
  615. * Emits when a portal is attached to the outlet.
  616. */
  617. _this.attached = new EventEmitter();
  618. return _this;
  619. }
  620. Object.defineProperty(CdkPortalOutlet.prototype, "portal", {
  621. /** Portal associated with the Portal outlet. */
  622. get: /**
  623. * Portal associated with the Portal outlet.
  624. * @return {?}
  625. */
  626. function () {
  627. return this._attachedPortal;
  628. },
  629. set: /**
  630. * @param {?} portal
  631. * @return {?}
  632. */
  633. function (portal) {
  634. // Ignore the cases where the `portal` is set to a falsy value before the lifecycle hooks have
  635. // run. This handles the cases where the user might do something like `<div cdkPortalOutlet>`
  636. // and attach a portal programmatically in the parent component. When Angular does the first CD
  637. // round, it will fire the setter with empty string, causing the user's content to be cleared.
  638. if (this.hasAttached() && !portal && !this._isInitialized) {
  639. return;
  640. }
  641. if (this.hasAttached()) {
  642. _super.prototype.detach.call(this);
  643. }
  644. if (portal) {
  645. _super.prototype.attach.call(this, portal);
  646. }
  647. this._attachedPortal = portal;
  648. },
  649. enumerable: true,
  650. configurable: true
  651. });
  652. Object.defineProperty(CdkPortalOutlet.prototype, "attachedRef", {
  653. /** Component or view reference that is attached to the portal. */
  654. get: /**
  655. * Component or view reference that is attached to the portal.
  656. * @return {?}
  657. */
  658. function () {
  659. return this._attachedRef;
  660. },
  661. enumerable: true,
  662. configurable: true
  663. });
  664. /**
  665. * @return {?}
  666. */
  667. CdkPortalOutlet.prototype.ngOnInit = /**
  668. * @return {?}
  669. */
  670. function () {
  671. this._isInitialized = true;
  672. };
  673. /**
  674. * @return {?}
  675. */
  676. CdkPortalOutlet.prototype.ngOnDestroy = /**
  677. * @return {?}
  678. */
  679. function () {
  680. _super.prototype.dispose.call(this);
  681. this._attachedPortal = null;
  682. this._attachedRef = null;
  683. };
  684. /**
  685. * Attach the given ComponentPortal to this PortalOutlet using the ComponentFactoryResolver.
  686. *
  687. * @param portal Portal to be attached to the portal outlet.
  688. * @returns Reference to the created component.
  689. */
  690. /**
  691. * Attach the given ComponentPortal to this PortalOutlet using the ComponentFactoryResolver.
  692. *
  693. * @template T
  694. * @param {?} portal Portal to be attached to the portal outlet.
  695. * @return {?} Reference to the created component.
  696. */
  697. CdkPortalOutlet.prototype.attachComponentPortal = /**
  698. * Attach the given ComponentPortal to this PortalOutlet using the ComponentFactoryResolver.
  699. *
  700. * @template T
  701. * @param {?} portal Portal to be attached to the portal outlet.
  702. * @return {?} Reference to the created component.
  703. */
  704. function (portal) {
  705. portal.setAttachedHost(this);
  706. // If the portal specifies an origin, use that as the logical location of the component
  707. // in the application tree. Otherwise use the location of this PortalOutlet.
  708. /** @type {?} */
  709. var viewContainerRef = portal.viewContainerRef != null ?
  710. portal.viewContainerRef :
  711. this._viewContainerRef;
  712. /** @type {?} */
  713. var resolver = portal.componentFactoryResolver || this._componentFactoryResolver;
  714. /** @type {?} */
  715. var componentFactory = resolver.resolveComponentFactory(portal.component);
  716. /** @type {?} */
  717. var ref = viewContainerRef.createComponent(componentFactory, viewContainerRef.length, portal.injector || viewContainerRef.injector);
  718. _super.prototype.setDisposeFn.call(this, (/**
  719. * @return {?}
  720. */
  721. function () { return ref.destroy(); }));
  722. this._attachedPortal = portal;
  723. this._attachedRef = ref;
  724. this.attached.emit(ref);
  725. return ref;
  726. };
  727. /**
  728. * Attach the given TemplatePortal to this PortlHost as an embedded View.
  729. * @param portal Portal to be attached.
  730. * @returns Reference to the created embedded view.
  731. */
  732. /**
  733. * Attach the given TemplatePortal to this PortlHost as an embedded View.
  734. * @template C
  735. * @param {?} portal Portal to be attached.
  736. * @return {?} Reference to the created embedded view.
  737. */
  738. CdkPortalOutlet.prototype.attachTemplatePortal = /**
  739. * Attach the given TemplatePortal to this PortlHost as an embedded View.
  740. * @template C
  741. * @param {?} portal Portal to be attached.
  742. * @return {?} Reference to the created embedded view.
  743. */
  744. function (portal) {
  745. var _this = this;
  746. portal.setAttachedHost(this);
  747. /** @type {?} */
  748. var viewRef = this._viewContainerRef.createEmbeddedView(portal.templateRef, portal.context);
  749. _super.prototype.setDisposeFn.call(this, (/**
  750. * @return {?}
  751. */
  752. function () { return _this._viewContainerRef.clear(); }));
  753. this._attachedPortal = portal;
  754. this._attachedRef = viewRef;
  755. this.attached.emit(viewRef);
  756. return viewRef;
  757. };
  758. CdkPortalOutlet.decorators = [
  759. { type: Directive, args: [{
  760. selector: '[cdkPortalOutlet]',
  761. exportAs: 'cdkPortalOutlet',
  762. inputs: ['portal: cdkPortalOutlet']
  763. },] },
  764. ];
  765. /** @nocollapse */
  766. CdkPortalOutlet.ctorParameters = function () { return [
  767. { type: ComponentFactoryResolver },
  768. { type: ViewContainerRef }
  769. ]; };
  770. CdkPortalOutlet.propDecorators = {
  771. attached: [{ type: Output }]
  772. };
  773. return CdkPortalOutlet;
  774. }(BasePortalOutlet));
  775. /**
  776. * @deprecated Use `CdkPortalOutlet` instead.
  777. * \@breaking-change 9.0.0
  778. */
  779. var PortalHostDirective = /** @class */ (function (_super) {
  780. __extends(PortalHostDirective, _super);
  781. function PortalHostDirective() {
  782. return _super !== null && _super.apply(this, arguments) || this;
  783. }
  784. PortalHostDirective.decorators = [
  785. { type: Directive, args: [{
  786. selector: '[cdkPortalHost], [portalHost]',
  787. exportAs: 'cdkPortalHost',
  788. inputs: ['portal: cdkPortalHost'],
  789. providers: [{
  790. provide: CdkPortalOutlet,
  791. useExisting: PortalHostDirective
  792. }]
  793. },] },
  794. ];
  795. return PortalHostDirective;
  796. }(CdkPortalOutlet));
  797. var PortalModule = /** @class */ (function () {
  798. function PortalModule() {
  799. }
  800. PortalModule.decorators = [
  801. { type: NgModule, args: [{
  802. exports: [CdkPortal, CdkPortalOutlet, TemplatePortalDirective, PortalHostDirective],
  803. declarations: [CdkPortal, CdkPortalOutlet, TemplatePortalDirective, PortalHostDirective],
  804. },] },
  805. ];
  806. return PortalModule;
  807. }());
  808. /**
  809. * @fileoverview added by tsickle
  810. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  811. */
  812. /**
  813. * Custom injector to be used when providing custom
  814. * injection tokens to components inside a portal.
  815. * \@docs-private
  816. */
  817. var /**
  818. * Custom injector to be used when providing custom
  819. * injection tokens to components inside a portal.
  820. * \@docs-private
  821. */
  822. PortalInjector = /** @class */ (function () {
  823. function PortalInjector(_parentInjector, _customTokens) {
  824. this._parentInjector = _parentInjector;
  825. this._customTokens = _customTokens;
  826. }
  827. /**
  828. * @param {?} token
  829. * @param {?=} notFoundValue
  830. * @return {?}
  831. */
  832. PortalInjector.prototype.get = /**
  833. * @param {?} token
  834. * @param {?=} notFoundValue
  835. * @return {?}
  836. */
  837. function (token, notFoundValue) {
  838. /** @type {?} */
  839. var value = this._customTokens.get(token);
  840. if (typeof value !== 'undefined') {
  841. return value;
  842. }
  843. return this._parentInjector.get(token, notFoundValue);
  844. };
  845. return PortalInjector;
  846. }());
  847. /**
  848. * @fileoverview added by tsickle
  849. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  850. */
  851. /**
  852. * @fileoverview added by tsickle
  853. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  854. */
  855. export { Portal, ComponentPortal, TemplatePortal, BasePortalOutlet, BasePortalHost, DomPortalOutlet, DomPortalHost, CdkPortal, TemplatePortalDirective, CdkPortalOutlet, PortalHostDirective, PortalModule, PortalInjector };
  856. //# sourceMappingURL=portal.es5.js.map