1 | var __extends = (this && this.__extends) || function (d, b) {
|
2 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
3 | function __() { this.constructor = d; }
|
4 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
5 | };
|
6 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
7 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
8 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
9 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
10 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
11 | };
|
12 | var __metadata = (this && this.__metadata) || function (k, v) {
|
13 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
14 | };
|
15 | import { NgModule, Directive, TemplateRef, ComponentFactoryResolver, ViewContainerRef } from '@angular/core';
|
16 | import { TemplatePortal, BasePortalHost } from './portal';
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | export var TemplatePortalDirective = (function (_super) {
|
27 | __extends(TemplatePortalDirective, _super);
|
28 | function TemplatePortalDirective(templateRef, viewContainerRef) {
|
29 | _super.call(this, templateRef, viewContainerRef);
|
30 | }
|
31 | TemplatePortalDirective = __decorate([
|
32 | Directive({
|
33 | selector: '[portal]',
|
34 | exportAs: 'portal',
|
35 | }),
|
36 | __metadata('design:paramtypes', [TemplateRef, ViewContainerRef])
|
37 | ], TemplatePortalDirective);
|
38 | return TemplatePortalDirective;
|
39 | }(TemplatePortal));
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | export var PortalHostDirective = (function (_super) {
|
48 | __extends(PortalHostDirective, _super);
|
49 | function PortalHostDirective(_componentFactoryResolver, _viewContainerRef) {
|
50 | _super.call(this);
|
51 | this._componentFactoryResolver = _componentFactoryResolver;
|
52 | this._viewContainerRef = _viewContainerRef;
|
53 | }
|
54 | Object.defineProperty(PortalHostDirective.prototype, "portal", {
|
55 | get: function () {
|
56 | return this._portal;
|
57 | },
|
58 | set: function (p) {
|
59 | this._replaceAttachedPortal(p);
|
60 | },
|
61 | enumerable: true,
|
62 | configurable: true
|
63 | });
|
64 |
|
65 | PortalHostDirective.prototype.attachComponentPortal = function (portal) {
|
66 | portal.setAttachedHost(this);
|
67 |
|
68 |
|
69 | var viewContainerRef = portal.viewContainerRef != null ?
|
70 | portal.viewContainerRef :
|
71 | this._viewContainerRef;
|
72 | var componentFactory = this._componentFactoryResolver.resolveComponentFactory(portal.component);
|
73 | var ref = viewContainerRef.createComponent(componentFactory, viewContainerRef.length, portal.injector || viewContainerRef.parentInjector);
|
74 | this.setDisposeFn(function () { return ref.destroy(); });
|
75 | return ref;
|
76 | };
|
77 |
|
78 | PortalHostDirective.prototype.attachTemplatePortal = function (portal) {
|
79 | var _this = this;
|
80 | portal.setAttachedHost(this);
|
81 | this._viewContainerRef.createEmbeddedView(portal.templateRef);
|
82 | this.setDisposeFn(function () { return _this._viewContainerRef.clear(); });
|
83 |
|
84 | return new Map();
|
85 | };
|
86 |
|
87 | PortalHostDirective.prototype._replaceAttachedPortal = function (p) {
|
88 | if (this.hasAttached()) {
|
89 | this.detach();
|
90 | }
|
91 | if (p) {
|
92 | this.attach(p);
|
93 | this._portal = p;
|
94 | }
|
95 | };
|
96 | PortalHostDirective = __decorate([
|
97 | Directive({
|
98 | selector: '[portalHost]',
|
99 | inputs: ['portal: portalHost']
|
100 | }),
|
101 | __metadata('design:paramtypes', [ComponentFactoryResolver, ViewContainerRef])
|
102 | ], PortalHostDirective);
|
103 | return PortalHostDirective;
|
104 | }(BasePortalHost));
|
105 | export var PortalModule = (function () {
|
106 | function PortalModule() {
|
107 | }
|
108 | PortalModule.forRoot = function () {
|
109 | return {
|
110 | ngModule: PortalModule,
|
111 | providers: []
|
112 | };
|
113 | };
|
114 | PortalModule = __decorate([
|
115 | NgModule({
|
116 | exports: [TemplatePortalDirective, PortalHostDirective],
|
117 | declarations: [TemplatePortalDirective, PortalHostDirective],
|
118 | }),
|
119 | __metadata('design:paramtypes', [])
|
120 | ], PortalModule);
|
121 | return PortalModule;
|
122 | }());
|
123 |
|
124 |
|