portal.d.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { ComponentRef, Injector, ViewContainerRef } from '@angular/core';
  2. export interface ComponentType<T> {
  3. new (...args: any[]): T;
  4. }
  5. /**
  6. * A `ComponentPortal` is a portal that instantiates some Component upon attachment.
  7. */
  8. export declare class ComponentPortal<T> {
  9. private _attachedHost?;
  10. /** The type of the component that will be instantiated for attachment. */
  11. component: ComponentType<T>;
  12. /**
  13. * [Optional] Where the attached component should live in Angular's *logical* component tree.
  14. * This is different from where the component *renders*, which is determined by the PortalHost.
  15. * The origin necessary when the host is outside of the Angular application context.
  16. */
  17. viewContainerRef: ViewContainerRef;
  18. /** Injector used for the instantiation of the component. */
  19. injector: Injector;
  20. constructor(component: ComponentType<T>, injector: Injector);
  21. /** Attach this portal to a host. */
  22. attach(host: BasePortalHost, newestOnTop: boolean): ComponentRef<any>;
  23. /** Detach this portal from its host */
  24. detach(): void;
  25. /** Whether this portal is attached to a host. */
  26. readonly isAttached: boolean;
  27. /**
  28. * Sets the PortalHost reference without performing `attach()`. This is used directly by
  29. * the PortalHost when it is performing an `attach()` or `detach()`.
  30. */
  31. setAttachedHost(host?: BasePortalHost): void;
  32. }
  33. /**
  34. * Partial implementation of PortalHost that only deals with attaching a
  35. * ComponentPortal
  36. */
  37. export declare abstract class BasePortalHost {
  38. /** The portal currently attached to the host. */
  39. private _attachedPortal?;
  40. /** A function that will permanently dispose this host. */
  41. private _disposeFn?;
  42. attach(portal: ComponentPortal<any>, newestOnTop: boolean): ComponentRef<any>;
  43. abstract attachComponentPortal<T>(portal: ComponentPortal<T>, newestOnTop: boolean): ComponentRef<T>;
  44. detach(): void;
  45. setDisposeFn(fn: () => void): void;
  46. }