Commit 64d4d9016556211e1cc48e39ca16be4d8644d9ba
1 parent
84647a07
Refactoring: replace deprecated PortalInjector
Showing
10 changed files
with
190 additions
and
101 deletions
@@ -14,14 +14,23 @@ | @@ -14,14 +14,23 @@ | ||
14 | /// limitations under the License. | 14 | /// limitations under the License. |
15 | /// | 15 | /// |
16 | 16 | ||
17 | -import { Component, Input, OnDestroy, OnInit, ViewChild, ViewContainerRef } from '@angular/core'; | 17 | +import { |
18 | + Component, | ||
19 | + Injector, | ||
20 | + Input, | ||
21 | + OnDestroy, | ||
22 | + OnInit, | ||
23 | + StaticProvider, | ||
24 | + ViewChild, | ||
25 | + ViewContainerRef | ||
26 | +} from '@angular/core'; | ||
18 | import { TooltipPosition } from '@angular/material/tooltip'; | 27 | import { TooltipPosition } from '@angular/material/tooltip'; |
19 | import { AliasInfo, IAliasController } from '@core/api/widget-api.models'; | 28 | import { AliasInfo, IAliasController } from '@core/api/widget-api.models'; |
20 | import { CdkOverlayOrigin, ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; | 29 | import { CdkOverlayOrigin, ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; |
21 | import { TranslateService } from '@ngx-translate/core'; | 30 | import { TranslateService } from '@ngx-translate/core'; |
22 | import { Subscription } from 'rxjs'; | 31 | import { Subscription } from 'rxjs'; |
23 | import { BreakpointObserver } from '@angular/cdk/layout'; | 32 | import { BreakpointObserver } from '@angular/cdk/layout'; |
24 | -import { ComponentPortal, PortalInjector } from '@angular/cdk/portal'; | 33 | +import { ComponentPortal } from '@angular/cdk/portal'; |
25 | import { | 34 | import { |
26 | ALIASES_ENTITY_SELECT_PANEL_DATA, | 35 | ALIASES_ENTITY_SELECT_PANEL_DATA, |
27 | AliasesEntitySelectPanelComponent, | 36 | AliasesEntitySelectPanelComponent, |
@@ -136,12 +145,12 @@ export class AliasesEntitySelectComponent implements OnInit, OnDestroy { | @@ -136,12 +145,12 @@ export class AliasesEntitySelectComponent implements OnInit, OnDestroy { | ||
136 | overlayRef.attach(new ComponentPortal(AliasesEntitySelectPanelComponent, this.viewContainerRef, injector)); | 145 | overlayRef.attach(new ComponentPortal(AliasesEntitySelectPanelComponent, this.viewContainerRef, injector)); |
137 | } | 146 | } |
138 | 147 | ||
139 | - private _createAliasesEntitySelectPanelInjector(overlayRef: OverlayRef, data: AliasesEntitySelectPanelData): PortalInjector { | ||
140 | - const injectionTokens = new WeakMap<any, any>([ | ||
141 | - [ALIASES_ENTITY_SELECT_PANEL_DATA, data], | ||
142 | - [OverlayRef, overlayRef] | ||
143 | - ]); | ||
144 | - return new PortalInjector(this.viewContainerRef.injector, injectionTokens); | 148 | + private _createAliasesEntitySelectPanelInjector(overlayRef: OverlayRef, data: AliasesEntitySelectPanelData): Injector { |
149 | + const providers: StaticProvider[] = [ | ||
150 | + {provide: ALIASES_ENTITY_SELECT_PANEL_DATA, useValue: data}, | ||
151 | + {provide: OverlayRef, useValue: overlayRef} | ||
152 | + ]; | ||
153 | + return Injector.create({parent: this.viewContainerRef.injector, providers}); | ||
145 | } | 154 | } |
146 | 155 | ||
147 | private updateDisplayValue() { | 156 | private updateDisplayValue() { |
@@ -19,9 +19,11 @@ import { | @@ -19,9 +19,11 @@ import { | ||
19 | ChangeDetectionStrategy, | 19 | ChangeDetectionStrategy, |
20 | Component, | 20 | Component, |
21 | ElementRef, | 21 | ElementRef, |
22 | + Injector, | ||
22 | Input, | 23 | Input, |
23 | NgZone, | 24 | NgZone, |
24 | OnInit, | 25 | OnInit, |
26 | + StaticProvider, | ||
25 | ViewChild, | 27 | ViewChild, |
26 | ViewContainerRef | 28 | ViewContainerRef |
27 | } from '@angular/core'; | 29 | } from '@angular/core'; |
@@ -62,7 +64,7 @@ import { | @@ -62,7 +64,7 @@ import { | ||
62 | EditAttributeValuePanelComponent, | 64 | EditAttributeValuePanelComponent, |
63 | EditAttributeValuePanelData | 65 | EditAttributeValuePanelData |
64 | } from './edit-attribute-value-panel.component'; | 66 | } from './edit-attribute-value-panel.component'; |
65 | -import { ComponentPortal, PortalInjector } from '@angular/cdk/portal'; | 67 | +import { ComponentPortal } from '@angular/cdk/portal'; |
66 | import { TelemetryWebsocketService } from '@core/ws/telemetry-websocket.service'; | 68 | import { TelemetryWebsocketService } from '@core/ws/telemetry-websocket.service'; |
67 | import { WidgetsBundle } from '@shared/models/widgets-bundle.model'; | 69 | import { WidgetsBundle } from '@shared/models/widgets-bundle.model'; |
68 | import { DataKey, Datasource, DatasourceType, Widget, widgetType } from '@shared/models/widget.models'; | 70 | import { DataKey, Datasource, DatasourceType, Widget, widgetType } from '@shared/models/widget.models'; |
@@ -319,13 +321,19 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI | @@ -319,13 +321,19 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI | ||
319 | overlayRef.backdropClick().subscribe(() => { | 321 | overlayRef.backdropClick().subscribe(() => { |
320 | overlayRef.dispose(); | 322 | overlayRef.dispose(); |
321 | }); | 323 | }); |
322 | - const injectionTokens = new WeakMap<any, any>([ | ||
323 | - [EDIT_ATTRIBUTE_VALUE_PANEL_DATA, { | ||
324 | - attributeValue: attribute.value | ||
325 | - } as EditAttributeValuePanelData], | ||
326 | - [OverlayRef, overlayRef] | ||
327 | - ]); | ||
328 | - const injector = new PortalInjector(this.viewContainerRef.injector, injectionTokens); | 324 | + const providers: StaticProvider[] = [ |
325 | + { | ||
326 | + provide: EDIT_ATTRIBUTE_VALUE_PANEL_DATA, | ||
327 | + useValue: { | ||
328 | + attributeValue: attribute.value | ||
329 | + } as EditAttributeValuePanelData | ||
330 | + }, | ||
331 | + { | ||
332 | + provide: OverlayRef, | ||
333 | + useValue: overlayRef | ||
334 | + } | ||
335 | + ]; | ||
336 | + const injector = Injector.create({parent: this.viewContainerRef.injector, providers}); | ||
329 | const componentRef = overlayRef.attach(new ComponentPortal(EditAttributeValuePanelComponent, | 337 | const componentRef = overlayRef.attach(new ComponentPortal(EditAttributeValuePanelComponent, |
330 | this.viewContainerRef, injector)); | 338 | this.viewContainerRef, injector)); |
331 | componentRef.onDestroy(() => { | 339 | componentRef.onDestroy(() => { |
@@ -14,7 +14,16 @@ | @@ -14,7 +14,16 @@ | ||
14 | /// limitations under the License. | 14 | /// limitations under the License. |
15 | /// | 15 | /// |
16 | 16 | ||
17 | -import { Component, Input, OnDestroy, OnInit, ViewChild, ViewContainerRef } from '@angular/core'; | 17 | +import { |
18 | + Component, | ||
19 | + Injector, | ||
20 | + Input, | ||
21 | + OnDestroy, | ||
22 | + OnInit, | ||
23 | + StaticProvider, | ||
24 | + ViewChild, | ||
25 | + ViewContainerRef | ||
26 | +} from '@angular/core'; | ||
18 | import { TooltipPosition } from '@angular/material/tooltip'; | 27 | import { TooltipPosition } from '@angular/material/tooltip'; |
19 | import { IAliasController } from '@core/api/widget-api.models'; | 28 | import { IAliasController } from '@core/api/widget-api.models'; |
20 | import { CdkOverlayOrigin, ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; | 29 | import { CdkOverlayOrigin, ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; |
@@ -28,7 +37,7 @@ import { | @@ -28,7 +37,7 @@ import { | ||
28 | FiltersEditPanelComponent, | 37 | FiltersEditPanelComponent, |
29 | FiltersEditPanelData | 38 | FiltersEditPanelData |
30 | } from '@home/components/filter/filters-edit-panel.component'; | 39 | } from '@home/components/filter/filters-edit-panel.component'; |
31 | -import { ComponentPortal, PortalInjector } from '@angular/cdk/portal'; | 40 | +import { ComponentPortal } from '@angular/cdk/portal'; |
32 | import { UserFilterDialogComponent, UserFilterDialogData } from '@home/components/filter/user-filter-dialog.component'; | 41 | import { UserFilterDialogComponent, UserFilterDialogData } from '@home/components/filter/user-filter-dialog.component'; |
33 | import { MatDialog } from '@angular/material/dialog'; | 42 | import { MatDialog } from '@angular/material/dialog'; |
34 | 43 | ||
@@ -153,12 +162,12 @@ export class FiltersEditComponent implements OnInit, OnDestroy { | @@ -153,12 +162,12 @@ export class FiltersEditComponent implements OnInit, OnDestroy { | ||
153 | } | 162 | } |
154 | } | 163 | } |
155 | 164 | ||
156 | - private _createFiltersEditPanelInjector(overlayRef: OverlayRef, data: FiltersEditPanelData): PortalInjector { | ||
157 | - const injectionTokens = new WeakMap<any, any>([ | ||
158 | - [FILTER_EDIT_PANEL_DATA, data], | ||
159 | - [OverlayRef, overlayRef] | ||
160 | - ]); | ||
161 | - return new PortalInjector(this.viewContainerRef.injector, injectionTokens); | 165 | + private _createFiltersEditPanelInjector(overlayRef: OverlayRef, data: FiltersEditPanelData): Injector { |
166 | + const providers: StaticProvider[] = [ | ||
167 | + {provide: FILTER_EDIT_PANEL_DATA, useValue: data}, | ||
168 | + {provide: OverlayRef, useValue: overlayRef} | ||
169 | + ]; | ||
170 | + return Injector.create({parent: this.viewContainerRef.injector, providers}); | ||
162 | } | 171 | } |
163 | 172 | ||
164 | private updateFiltersInfo() { | 173 | private updateFiltersInfo() { |
@@ -14,11 +14,22 @@ | @@ -14,11 +14,22 @@ | ||
14 | /// limitations under the License. | 14 | /// limitations under the License. |
15 | /// | 15 | /// |
16 | 16 | ||
17 | -import { Component, forwardRef, Inject, Input, OnDestroy, OnInit, ViewChild, ViewContainerRef } from '@angular/core'; | 17 | +import { |
18 | + Component, | ||
19 | + forwardRef, | ||
20 | + Inject, | ||
21 | + Injector, | ||
22 | + Input, | ||
23 | + OnDestroy, | ||
24 | + OnInit, | ||
25 | + StaticProvider, | ||
26 | + ViewChild, | ||
27 | + ViewContainerRef | ||
28 | +} from '@angular/core'; | ||
18 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | 29 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; |
19 | import { DOCUMENT } from '@angular/common'; | 30 | import { DOCUMENT } from '@angular/common'; |
20 | import { CdkOverlayOrigin, ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; | 31 | import { CdkOverlayOrigin, ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; |
21 | -import { ComponentPortal, PortalInjector } from '@angular/cdk/portal'; | 32 | +import { ComponentPortal } from '@angular/cdk/portal'; |
22 | import { MediaBreakpoints } from '@shared/models/constants'; | 33 | import { MediaBreakpoints } from '@shared/models/constants'; |
23 | import { BreakpointObserver } from '@angular/cdk/layout'; | 34 | import { BreakpointObserver } from '@angular/cdk/layout'; |
24 | import { WINDOW } from '@core/services/window.service'; | 35 | import { WINDOW } from '@core/services/window.service'; |
@@ -140,12 +151,12 @@ export class LegendConfigComponent implements OnInit, OnDestroy, ControlValueAcc | @@ -140,12 +151,12 @@ export class LegendConfigComponent implements OnInit, OnDestroy, ControlValueAcc | ||
140 | overlayRef.attach(new ComponentPortal(LegendConfigPanelComponent, this.viewContainerRef, injector)); | 151 | overlayRef.attach(new ComponentPortal(LegendConfigPanelComponent, this.viewContainerRef, injector)); |
141 | } | 152 | } |
142 | 153 | ||
143 | - private _createLegendConfigPanelInjector(overlayRef: OverlayRef, data: LegendConfigPanelData): PortalInjector { | ||
144 | - const injectionTokens = new WeakMap<any, any>([ | ||
145 | - [LEGEND_CONFIG_PANEL_DATA, data], | ||
146 | - [OverlayRef, overlayRef] | ||
147 | - ]); | ||
148 | - return new PortalInjector(this.viewContainerRef.injector, injectionTokens); | 154 | + private _createLegendConfigPanelInjector(overlayRef: OverlayRef, data: LegendConfigPanelData): Injector { |
155 | + const providers: StaticProvider[] = [ | ||
156 | + {provide: LEGEND_CONFIG_PANEL_DATA, useValue: data}, | ||
157 | + {provide: OverlayRef, useValue: overlayRef} | ||
158 | + ]; | ||
159 | + return Injector.create({parent: this.viewContainerRef.injector, providers}); | ||
149 | } | 160 | } |
150 | 161 | ||
151 | registerOnChange(fn: any): void { | 162 | registerOnChange(fn: any): void { |
@@ -19,9 +19,11 @@ import { | @@ -19,9 +19,11 @@ import { | ||
19 | Component, | 19 | Component, |
20 | ElementRef, | 20 | ElementRef, |
21 | EventEmitter, | 21 | EventEmitter, |
22 | + Injector, | ||
22 | Input, | 23 | Input, |
23 | NgZone, | 24 | NgZone, |
24 | OnInit, | 25 | OnInit, |
26 | + StaticProvider, | ||
25 | ViewChild, | 27 | ViewChild, |
26 | ViewContainerRef | 28 | ViewContainerRef |
27 | } from '@angular/core'; | 29 | } from '@angular/core'; |
@@ -64,7 +66,7 @@ import { | @@ -64,7 +66,7 @@ import { | ||
64 | widthStyle | 66 | widthStyle |
65 | } from '@home/components/widget/lib/table-widget.models'; | 67 | } from '@home/components/widget/lib/table-widget.models'; |
66 | import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; | 68 | import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; |
67 | -import { ComponentPortal, PortalInjector } from '@angular/cdk/portal'; | 69 | +import { ComponentPortal } from '@angular/cdk/portal'; |
68 | import { | 70 | import { |
69 | DISPLAY_COLUMNS_PANEL_DATA, | 71 | DISPLAY_COLUMNS_PANEL_DATA, |
70 | DisplayColumnsPanelComponent, | 72 | DisplayColumnsPanelComponent, |
@@ -452,20 +454,26 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | @@ -452,20 +454,26 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | ||
452 | }; | 454 | }; |
453 | }); | 455 | }); |
454 | 456 | ||
455 | - const injectionTokens = new WeakMap<any, any>([ | ||
456 | - [DISPLAY_COLUMNS_PANEL_DATA, { | ||
457 | - columns, | ||
458 | - columnsUpdated: (newColumns) => { | ||
459 | - this.displayedColumns = newColumns.filter(column => column.display).map(column => column.def); | ||
460 | - if (this.enableSelection) { | ||
461 | - this.displayedColumns.unshift('select'); | 457 | + const providers: StaticProvider[] = [ |
458 | + { | ||
459 | + provide: DISPLAY_COLUMNS_PANEL_DATA, | ||
460 | + useValue: { | ||
461 | + columns, | ||
462 | + columnsUpdated: (newColumns) => { | ||
463 | + this.displayedColumns = newColumns.filter(column => column.display).map(column => column.def); | ||
464 | + if (this.enableSelection) { | ||
465 | + this.displayedColumns.unshift('select'); | ||
466 | + } | ||
467 | + this.displayedColumns.push('actions'); | ||
462 | } | 468 | } |
463 | - this.displayedColumns.push('actions'); | ||
464 | - } | ||
465 | - } as DisplayColumnsPanelData], | ||
466 | - [OverlayRef, overlayRef] | ||
467 | - ]); | ||
468 | - const injector = new PortalInjector(this.viewContainerRef.injector, injectionTokens); | 469 | + } as DisplayColumnsPanelData |
470 | + }, | ||
471 | + { | ||
472 | + provide: OverlayRef, | ||
473 | + useValue: overlayRef | ||
474 | + } | ||
475 | + ]; | ||
476 | + const injector = Injector.create({parent: this.viewContainerRef.injector, providers}); | ||
469 | overlayRef.attach(new ComponentPortal(DisplayColumnsPanelComponent, | 477 | overlayRef.attach(new ComponentPortal(DisplayColumnsPanelComponent, |
470 | this.viewContainerRef, injector)); | 478 | this.viewContainerRef, injector)); |
471 | this.ctx.detectChanges(); | 479 | this.ctx.detectChanges(); |
@@ -492,15 +500,21 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | @@ -492,15 +500,21 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, | ||
492 | overlayRef.backdropClick().subscribe(() => { | 500 | overlayRef.backdropClick().subscribe(() => { |
493 | overlayRef.dispose(); | 501 | overlayRef.dispose(); |
494 | }); | 502 | }); |
495 | - const injectionTokens = new WeakMap<any, any>([ | ||
496 | - [ALARM_FILTER_PANEL_DATA, { | ||
497 | - statusList: this.pageLink.statusList, | ||
498 | - severityList: this.pageLink.severityList, | ||
499 | - typeList: this.pageLink.typeList | ||
500 | - } as AlarmFilterPanelData], | ||
501 | - [OverlayRef, overlayRef] | ||
502 | - ]); | ||
503 | - const injector = new PortalInjector(this.viewContainerRef.injector, injectionTokens); | 503 | + const providers: StaticProvider[] = [ |
504 | + { | ||
505 | + provide: ALARM_FILTER_PANEL_DATA, | ||
506 | + useValue: { | ||
507 | + statusList: this.pageLink.statusList, | ||
508 | + severityList: this.pageLink.severityList, | ||
509 | + typeList: this.pageLink.typeList | ||
510 | + } as AlarmFilterPanelData | ||
511 | + }, | ||
512 | + { | ||
513 | + provide: OverlayRef, | ||
514 | + useValue: overlayRef | ||
515 | + } | ||
516 | + ]; | ||
517 | + const injector = Injector.create({parent: this.viewContainerRef.injector, providers}); | ||
504 | const componentRef = overlayRef.attach(new ComponentPortal(AlarmFilterPanelComponent, | 518 | const componentRef = overlayRef.attach(new ComponentPortal(AlarmFilterPanelComponent, |
505 | this.viewContainerRef, injector)); | 519 | this.viewContainerRef, injector)); |
506 | componentRef.onDestroy(() => { | 520 | componentRef.onDestroy(() => { |
@@ -18,9 +18,11 @@ import { | @@ -18,9 +18,11 @@ import { | ||
18 | Component, | 18 | Component, |
19 | Inject, | 19 | Inject, |
20 | InjectionToken, | 20 | InjectionToken, |
21 | + Injector, | ||
21 | Input, | 22 | Input, |
22 | OnDestroy, | 23 | OnDestroy, |
23 | OnInit, | 24 | OnInit, |
25 | + StaticProvider, | ||
24 | ViewChild, | 26 | ViewChild, |
25 | ViewContainerRef, | 27 | ViewContainerRef, |
26 | ViewEncapsulation | 28 | ViewEncapsulation |
@@ -41,7 +43,7 @@ import { | @@ -41,7 +43,7 @@ import { | ||
41 | import { KeyValue } from '@angular/common'; | 43 | import { KeyValue } from '@angular/common'; |
42 | import * as _moment from 'moment'; | 44 | import * as _moment from 'moment'; |
43 | import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; | 45 | import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; |
44 | -import { ComponentPortal, PortalInjector } from '@angular/cdk/portal'; | 46 | +import { ComponentPortal } from '@angular/cdk/portal'; |
45 | import { MatSelect } from '@angular/material/select'; | 47 | import { MatSelect } from '@angular/material/select'; |
46 | import { Subscription } from 'rxjs'; | 48 | import { Subscription } from 'rxjs'; |
47 | import { HistoryWindowType, TimewindowType } from '@shared/models/time/time.models'; | 49 | import { HistoryWindowType, TimewindowType } from '@shared/models/time/time.models'; |
@@ -142,18 +144,24 @@ export class DateRangeNavigatorWidgetComponent extends PageComponent implements | @@ -142,18 +144,24 @@ export class DateRangeNavigatorWidgetComponent extends PageComponent implements | ||
142 | overlayRef.backdropClick().subscribe(() => { | 144 | overlayRef.backdropClick().subscribe(() => { |
143 | overlayRef.dispose(); | 145 | overlayRef.dispose(); |
144 | }); | 146 | }); |
145 | - const injectionTokens = new WeakMap<any, any>([ | ||
146 | - [DATE_RANGE_NAVIGATOR_PANEL_DATA, { | ||
147 | - model: cloneDateRangeNavigatorModel(this.advancedModel), | ||
148 | - settings: this.settings, | ||
149 | - onChange: model => { | ||
150 | - this.advancedModel = model; | ||
151 | - this.triggerChange(); | ||
152 | - } | ||
153 | - } as DateRangeNavigatorPanelData], | ||
154 | - [OverlayRef, overlayRef] | ||
155 | - ]); | ||
156 | - const injector = new PortalInjector(this.viewContainerRef.injector, injectionTokens); | 147 | + const providers: StaticProvider[] = [ |
148 | + { | ||
149 | + provide: DATE_RANGE_NAVIGATOR_PANEL_DATA, | ||
150 | + useValue: { | ||
151 | + model: cloneDateRangeNavigatorModel(this.advancedModel), | ||
152 | + settings: this.settings, | ||
153 | + onChange: model => { | ||
154 | + this.advancedModel = model; | ||
155 | + this.triggerChange(); | ||
156 | + } | ||
157 | + } as DateRangeNavigatorPanelData | ||
158 | + }, | ||
159 | + { | ||
160 | + provide: OverlayRef, | ||
161 | + useValue: overlayRef | ||
162 | + } | ||
163 | + ]; | ||
164 | + const injector = Injector.create({parent: this.viewContainerRef.injector, providers}); | ||
157 | overlayRef.attach(new ComponentPortal(DateRangeNavigatorPanelComponent, | 165 | overlayRef.attach(new ComponentPortal(DateRangeNavigatorPanelComponent, |
158 | this.viewContainerRef, injector)); | 166 | this.viewContainerRef, injector)); |
159 | this.ctx.detectChanges(); | 167 | this.ctx.detectChanges(); |
@@ -18,9 +18,11 @@ import { | @@ -18,9 +18,11 @@ import { | ||
18 | AfterViewInit, | 18 | AfterViewInit, |
19 | Component, | 19 | Component, |
20 | ElementRef, | 20 | ElementRef, |
21 | + Injector, | ||
21 | Input, | 22 | Input, |
22 | NgZone, | 23 | NgZone, |
23 | OnInit, | 24 | OnInit, |
25 | + StaticProvider, | ||
24 | ViewChild, | 26 | ViewChild, |
25 | ViewContainerRef | 27 | ViewContainerRef |
26 | } from '@angular/core'; | 28 | } from '@angular/core'; |
@@ -70,7 +72,7 @@ import { | @@ -70,7 +72,7 @@ import { | ||
70 | widthStyle | 72 | widthStyle |
71 | } from '@home/components/widget/lib/table-widget.models'; | 73 | } from '@home/components/widget/lib/table-widget.models'; |
72 | import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; | 74 | import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; |
73 | -import { ComponentPortal, PortalInjector } from '@angular/cdk/portal'; | 75 | +import { ComponentPortal } from '@angular/cdk/portal'; |
74 | import { | 76 | import { |
75 | DISPLAY_COLUMNS_PANEL_DATA, | 77 | DISPLAY_COLUMNS_PANEL_DATA, |
76 | DisplayColumnsPanelComponent, | 78 | DisplayColumnsPanelComponent, |
@@ -422,17 +424,23 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni | @@ -422,17 +424,23 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni | ||
422 | }; | 424 | }; |
423 | }); | 425 | }); |
424 | 426 | ||
425 | - const injectionTokens = new WeakMap<any, any>([ | ||
426 | - [DISPLAY_COLUMNS_PANEL_DATA, { | ||
427 | - columns, | ||
428 | - columnsUpdated: (newColumns) => { | ||
429 | - this.displayedColumns = newColumns.filter(column => column.display).map(column => column.def); | ||
430 | - this.displayedColumns.push('actions'); | ||
431 | - } | ||
432 | - } as DisplayColumnsPanelData], | ||
433 | - [OverlayRef, overlayRef] | ||
434 | - ]); | ||
435 | - const injector = new PortalInjector(this.viewContainerRef.injector, injectionTokens); | 427 | + const providers: StaticProvider[] = [ |
428 | + { | ||
429 | + provide: DISPLAY_COLUMNS_PANEL_DATA, | ||
430 | + useValue: { | ||
431 | + columns, | ||
432 | + columnsUpdated: (newColumns) => { | ||
433 | + this.displayedColumns = newColumns.filter(column => column.display).map(column => column.def); | ||
434 | + this.displayedColumns.push('actions'); | ||
435 | + } | ||
436 | + } as DisplayColumnsPanelData | ||
437 | + }, | ||
438 | + { | ||
439 | + provide: OverlayRef, | ||
440 | + useValue: overlayRef | ||
441 | + } | ||
442 | + ]; | ||
443 | + const injector = Injector.create({parent: this.viewContainerRef.injector, providers}); | ||
436 | overlayRef.attach(new ComponentPortal(DisplayColumnsPanelComponent, | 444 | overlayRef.attach(new ComponentPortal(DisplayColumnsPanelComponent, |
437 | this.viewContainerRef, injector)); | 445 | this.viewContainerRef, injector)); |
438 | this.ctx.detectChanges(); | 446 | this.ctx.detectChanges(); |
@@ -14,7 +14,17 @@ | @@ -14,7 +14,17 @@ | ||
14 | /// limitations under the License. | 14 | /// limitations under the License. |
15 | /// | 15 | /// |
16 | 16 | ||
17 | -import { Component, forwardRef, Inject, Input, OnInit, ViewChild, ViewContainerRef } from '@angular/core'; | 17 | +import { |
18 | + Component, | ||
19 | + forwardRef, | ||
20 | + Inject, | ||
21 | + Injector, | ||
22 | + Input, | ||
23 | + OnInit, | ||
24 | + StaticProvider, | ||
25 | + ViewChild, | ||
26 | + ViewContainerRef | ||
27 | +} from '@angular/core'; | ||
18 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | 28 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; |
19 | import { Observable, of } from 'rxjs'; | 29 | import { Observable, of } from 'rxjs'; |
20 | import { PageLink } from '@shared/models/page/page-link'; | 30 | import { PageLink } from '@shared/models/page/page-link'; |
@@ -32,7 +42,7 @@ import { CdkOverlayOrigin, ConnectedPosition, Overlay, OverlayConfig, OverlayRef | @@ -32,7 +42,7 @@ import { CdkOverlayOrigin, ConnectedPosition, Overlay, OverlayConfig, OverlayRef | ||
32 | import { BreakpointObserver } from '@angular/cdk/layout'; | 42 | import { BreakpointObserver } from '@angular/cdk/layout'; |
33 | import { DOCUMENT } from '@angular/common'; | 43 | import { DOCUMENT } from '@angular/common'; |
34 | import { WINDOW } from '@core/services/window.service'; | 44 | import { WINDOW } from '@core/services/window.service'; |
35 | -import { ComponentPortal, PortalInjector } from '@angular/cdk/portal'; | 45 | +import { ComponentPortal } from '@angular/cdk/portal'; |
36 | import { | 46 | import { |
37 | DASHBOARD_SELECT_PANEL_DATA, | 47 | DASHBOARD_SELECT_PANEL_DATA, |
38 | DashboardSelectPanelComponent, | 48 | DashboardSelectPanelComponent, |
@@ -186,12 +196,12 @@ export class DashboardSelectComponent implements ControlValueAccessor, OnInit { | @@ -186,12 +196,12 @@ export class DashboardSelectComponent implements ControlValueAccessor, OnInit { | ||
186 | overlayRef.attach(new ComponentPortal(DashboardSelectPanelComponent, this.viewContainerRef, injector)); | 196 | overlayRef.attach(new ComponentPortal(DashboardSelectPanelComponent, this.viewContainerRef, injector)); |
187 | } | 197 | } |
188 | 198 | ||
189 | - private _createDashboardSelectPanelInjector(overlayRef: OverlayRef, data: DashboardSelectPanelData): PortalInjector { | ||
190 | - const injectionTokens = new WeakMap<any, any>([ | ||
191 | - [DASHBOARD_SELECT_PANEL_DATA, data], | ||
192 | - [OverlayRef, overlayRef] | ||
193 | - ]); | ||
194 | - return new PortalInjector(this.viewContainerRef.injector, injectionTokens); | 199 | + private _createDashboardSelectPanelInjector(overlayRef: OverlayRef, data: DashboardSelectPanelData): Injector { |
200 | + const providers: StaticProvider[] = [ | ||
201 | + {provide: DASHBOARD_SELECT_PANEL_DATA, useValue: data}, | ||
202 | + {provide: OverlayRef, useValue: overlayRef} | ||
203 | + ]; | ||
204 | + return Injector.create({parent: this.viewContainerRef.injector, providers}); | ||
195 | } | 205 | } |
196 | 206 | ||
197 | private updateView() { | 207 | private updateView() { |
@@ -14,7 +14,18 @@ | @@ -14,7 +14,18 @@ | ||
14 | /// limitations under the License. | 14 | /// limitations under the License. |
15 | /// | 15 | /// |
16 | 16 | ||
17 | -import { Component, forwardRef, Inject, Input, OnDestroy, OnInit, ViewChild, ViewContainerRef } from '@angular/core'; | 17 | +import { |
18 | + Component, | ||
19 | + forwardRef, | ||
20 | + Inject, | ||
21 | + Injector, | ||
22 | + Input, | ||
23 | + OnDestroy, | ||
24 | + OnInit, | ||
25 | + StaticProvider, | ||
26 | + ViewChild, | ||
27 | + ViewContainerRef | ||
28 | +} from '@angular/core'; | ||
18 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | 29 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; |
19 | import { TranslateService } from '@ngx-translate/core'; | 30 | import { TranslateService } from '@ngx-translate/core'; |
20 | import { MillisecondsToTimeStringPipe } from '@shared/pipe/milliseconds-to-time-string.pipe'; | 31 | import { MillisecondsToTimeStringPipe } from '@shared/pipe/milliseconds-to-time-string.pipe'; |
@@ -32,7 +43,7 @@ import { | @@ -32,7 +43,7 @@ import { | ||
32 | TimewindowPanelComponent, | 43 | TimewindowPanelComponent, |
33 | TimewindowPanelData | 44 | TimewindowPanelData |
34 | } from '@shared/components/time/timewindow-panel.component'; | 45 | } from '@shared/components/time/timewindow-panel.component'; |
35 | -import { ComponentPortal, PortalInjector } from '@angular/cdk/portal'; | 46 | +import { ComponentPortal } from '@angular/cdk/portal'; |
36 | import { MediaBreakpoints } from '@shared/models/constants'; | 47 | import { MediaBreakpoints } from '@shared/models/constants'; |
37 | import { BreakpointObserver } from '@angular/cdk/layout'; | 48 | import { BreakpointObserver } from '@angular/cdk/layout'; |
38 | import { WINDOW } from '@core/services/window.service'; | 49 | import { WINDOW } from '@core/services/window.service'; |
@@ -229,12 +240,12 @@ export class TimewindowComponent implements OnInit, OnDestroy, ControlValueAcces | @@ -229,12 +240,12 @@ export class TimewindowComponent implements OnInit, OnDestroy, ControlValueAcces | ||
229 | }); | 240 | }); |
230 | } | 241 | } |
231 | 242 | ||
232 | - private _createTimewindowPanelInjector(overlayRef: OverlayRef, data: TimewindowPanelData): PortalInjector { | ||
233 | - const injectionTokens = new WeakMap<any, any>([ | ||
234 | - [TIMEWINDOW_PANEL_DATA, data], | ||
235 | - [OverlayRef, overlayRef] | ||
236 | - ]); | ||
237 | - return new PortalInjector(this.viewContainerRef.injector, injectionTokens); | 243 | + private _createTimewindowPanelInjector(overlayRef: OverlayRef, data: TimewindowPanelData): Injector { |
244 | + const providers: StaticProvider[] = [ | ||
245 | + {provide: TIMEWINDOW_PANEL_DATA, useValue: data}, | ||
246 | + {provide: OverlayRef, useValue: overlayRef} | ||
247 | + ]; | ||
248 | + return Injector.create({parent: this.viewContainerRef.injector, providers}); | ||
238 | } | 249 | } |
239 | 250 | ||
240 | registerOnChange(fn: any): void { | 251 | registerOnChange(fn: any): void { |
@@ -20,9 +20,11 @@ import { | @@ -20,9 +20,11 @@ import { | ||
20 | Directive, | 20 | Directive, |
21 | ElementRef, HostBinding, | 21 | ElementRef, HostBinding, |
22 | Inject, | 22 | Inject, |
23 | + Injector, | ||
23 | Input, | 24 | Input, |
24 | NgZone, | 25 | NgZone, |
25 | OnDestroy, Optional, | 26 | OnDestroy, Optional, |
27 | + StaticProvider, | ||
26 | ViewChild, | 28 | ViewChild, |
27 | ViewContainerRef | 29 | ViewContainerRef |
28 | } from '@angular/core'; | 30 | } from '@angular/core'; |
@@ -34,7 +36,6 @@ import { BreakpointObserver } from '@angular/cdk/layout'; | @@ -34,7 +36,6 @@ import { BreakpointObserver } from '@angular/cdk/layout'; | ||
34 | import { MediaBreakpoints } from '@shared/models/constants'; | 36 | import { MediaBreakpoints } from '@shared/models/constants'; |
35 | import { MatButton } from '@angular/material/button'; | 37 | import { MatButton } from '@angular/material/button'; |
36 | import Timeout = NodeJS.Timeout; | 38 | import Timeout = NodeJS.Timeout; |
37 | -import { PortalInjector } from '@angular/cdk/portal'; | ||
38 | 39 | ||
39 | @Directive({ | 40 | @Directive({ |
40 | selector: '[tb-toast]' | 41 | selector: '[tb-toast]' |
@@ -138,10 +139,10 @@ export class ToastDirective implements AfterViewInit, OnDestroy { | @@ -138,10 +139,10 @@ export class ToastDirective implements AfterViewInit, OnDestroy { | ||
138 | this.toastComponentRef.destroy(); | 139 | this.toastComponentRef.destroy(); |
139 | } | 140 | } |
140 | }; | 141 | }; |
141 | - const injectionTokens = new WeakMap<any, any>([ | ||
142 | - [MAT_SNACK_BAR_DATA, data] | ||
143 | - ]); | ||
144 | - const injector = new PortalInjector(this.viewContainerRef.injector, injectionTokens); | 142 | + const providers: StaticProvider[] = [ |
143 | + {provide: MAT_SNACK_BAR_DATA, useValue: data} | ||
144 | + ]; | ||
145 | + const injector = Injector.create({parent: this.viewContainerRef.injector, providers}); | ||
145 | this.toastComponentRef = this.viewContainerRef.createComponent(componentFactory, 0, injector); | 146 | this.toastComponentRef = this.viewContainerRef.createComponent(componentFactory, 0, injector); |
146 | this.cd.detectChanges(); | 147 | this.cd.detectChanges(); |
147 | 148 |