UNPKG

3.62 kBTypeScriptView Raw
1import { TemplateRef, ViewContainerRef, ElementRef, ComponentRef, Injector } from '@angular/core';
2import { ComponentType } from '../overlay/generic-component-type';
3/**
4 * A `Portal` is something that you want to render somewhere else.
5 * It can be attach to / detached from a `PortalHost`.
6 */
7export declare abstract class Portal<T> {
8 private _attachedHost;
9 /** Attach this portal to a host. */
10 attach(host: PortalHost): T;
11 /** Detach this portal from its host */
12 detach(): void;
13 /** Whether this portal is attached to a host. */
14 readonly isAttached: boolean;
15 /**
16 * Sets the PortalHost reference without performing `attach()`. This is used directly by
17 * the PortalHost when it is performing an `attach()` or `detatch()`.
18 */
19 setAttachedHost(host: PortalHost): void;
20}
21/**
22 * A `ComponentPortal` is a portal that instantiates some Component upon attachment.
23 */
24export declare class ComponentPortal<T> extends Portal<ComponentRef<T>> {
25 /** The type of the component that will be instantiated for attachment. */
26 component: ComponentType<T>;
27 /**
28 * [Optional] Where the attached component should live in Angular's *logical* component tree.
29 * This is different from where the component *renders*, which is determined by the PortalHost.
30 * The origin necessary when the host is outside of the Angular application context.
31 */
32 viewContainerRef: ViewContainerRef;
33 /** [Optional] Injector used for the instantiation of the component. */
34 injector: Injector;
35 constructor(component: ComponentType<T>, viewContainerRef?: ViewContainerRef, injector?: Injector);
36}
37/**
38 * A `TemplatePortal` is a portal that represents some embedded template (TemplateRef).
39 */
40export declare class TemplatePortal extends Portal<Map<string, any>> {
41 /** The embedded template that will be used to instantiate an embedded View in the host. */
42 templateRef: TemplateRef<any>;
43 /** Reference to the ViewContainer into which the template will be stamped out. */
44 viewContainerRef: ViewContainerRef;
45 /**
46 * Additional locals for the instantiated embedded view.
47 * These locals can be seen as "exports" for the template, such as how ngFor has
48 * index / event / odd.
49 * See https://angular.io/docs/ts/latest/api/core/EmbeddedViewRef-class.html
50 */
51 locals: Map<string, any>;
52 constructor(template: TemplateRef<any>, viewContainerRef: ViewContainerRef);
53 readonly origin: ElementRef;
54 attach(host: PortalHost, locals?: Map<string, any>): Map<string, any>;
55 detach(): void;
56}
57/**
58 * A `PortalHost` is an space that can contain a single `Portal`.
59 */
60export interface PortalHost {
61 attach(portal: Portal<any>): any;
62 detach(): any;
63 dispose(): void;
64 hasAttached(): boolean;
65}
66/**
67 * Partial implementation of PortalHost that only deals with attaching either a
68 * ComponentPortal or a TemplatePortal.
69 */
70export declare abstract class BasePortalHost implements PortalHost {
71 /** The portal currently attached to the host. */
72 private _attachedPortal;
73 /** A function that will permanently dispose this host. */
74 private _disposeFn;
75 /** Whether this host has already been permanently disposed. */
76 private _isDisposed;
77 /** Whether this host has an attached portal. */
78 hasAttached(): boolean;
79 attach(portal: Portal<any>): any;
80 abstract attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T>;
81 abstract attachTemplatePortal(portal: TemplatePortal): Map<string, any>;
82 detach(): void;
83 dispose(): void;
84 setDisposeFn(fn: () => void): void;
85}