From 89cf83820a7fb33e101c9ccc4a7015c20bb58ab1 Mon Sep 17 00:00:00 2001 From: Nikita Poltoratsky Date: Tue, 2 Oct 2018 19:05:31 +0300 Subject: [PATCH 1/4] fix(datepicker): provide componentFactoryResolver in calendar components --- .../components/cdk/overlay/overlay-container.ts | 12 ++++++++++-- src/playground/playground.module.ts | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/framework/theme/components/cdk/overlay/overlay-container.ts b/src/framework/theme/components/cdk/overlay/overlay-container.ts index dbbbcd792a..182668efa9 100644 --- a/src/framework/theme/components/cdk/overlay/overlay-container.ts +++ b/src/framework/theme/components/cdk/overlay/overlay-container.ts @@ -1,5 +1,6 @@ import { Component, + ComponentFactoryResolver, ComponentRef, EmbeddedViewRef, HostBinding, @@ -9,7 +10,7 @@ import { } from '@angular/core'; import { NbPosition } from './overlay-position'; -import { NbComponentPortal, NbTemplatePortal } from './mapping'; +import { NbComponentPortal, NbPortalInjector, NbTemplatePortal } from './mapping'; export abstract class NbPositionedContainer { @Input() position: NbPosition; @@ -54,7 +55,8 @@ export class NbOverlayContainerComponent { attachComponentPortal(portal: NbComponentPortal): ComponentRef { const factory = portal.cfr.resolveComponentFactory(portal.component); - return this.vcr.createComponent(factory); + const injector = this.createChildInjector(portal.cfr); + return this.vcr.createComponent(factory, null, injector); } attachTemplatePortal(portal: NbTemplatePortal): EmbeddedViewRef { @@ -64,4 +66,10 @@ export class NbOverlayContainerComponent { attachStringContent(content: string) { this.content = content; } + + protected createChildInjector(cfr: ComponentFactoryResolver): NbPortalInjector { + return new NbPortalInjector(this.injector, new WeakMap([ + [ComponentFactoryResolver, cfr], + ])); + } } diff --git a/src/playground/playground.module.ts b/src/playground/playground.module.ts index 68ec813b42..3902b4c524 100644 --- a/src/playground/playground.module.ts +++ b/src/playground/playground.module.ts @@ -262,7 +262,7 @@ export const NB_MODULES = [ NbMenuModule.forRoot(), NbActionsModule, NbSearchModule, - NbThemeModule.forRoot({ name: 'default' }), + NbThemeModule, NbTabsetModule, NbRouteTabsetModule, NbUserModule, From 166dc146c326805b55f636057d64413314bc9acd Mon Sep 17 00:00:00 2001 From: Nikita Poltoratsky Date: Wed, 3 Oct 2018 08:30:57 +0300 Subject: [PATCH 2/4] fix(toastr): provide componentFactoryResolver --- src/app/app.module.ts | 3 ++- src/framework/theme/components/toastr/toastr.service.ts | 7 ++++--- src/playground/playground.module.ts | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 1eae08ed79..81fa5475e9 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -10,7 +10,7 @@ import { FormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; import { HttpClientModule } from '@angular/common/http'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { NbThemeModule } from '@nebular/theme'; +import { NbThemeModule, NbToastrModule } from '@nebular/theme'; import { NbAppComponent } from './app.component'; import { NbLayoutDirectionToggleComponent } from './layout-direction-toggle/layout-direction-toggle.component'; @@ -24,6 +24,7 @@ import { NbLayoutThemeToggleComponent } from './layout-theme-toggle/layout-theme BrowserAnimationsModule, FormsModule, HttpClientModule, + NbToastrModule.forRoot(), RouterModule.forRoot([ { path: '', diff --git a/src/framework/theme/components/toastr/toastr.service.ts b/src/framework/theme/components/toastr/toastr.service.ts index a6eb751a1a..277ccd955c 100644 --- a/src/framework/theme/components/toastr/toastr.service.ts +++ b/src/framework/theme/components/toastr/toastr.service.ts @@ -4,7 +4,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. */ -import { ComponentRef, Inject, Injectable } from '@angular/core'; +import { ComponentFactoryResolver, ComponentRef, Inject, Injectable } from '@angular/core'; import { NbComponentPortal, @@ -99,7 +99,8 @@ export class NbToastrContainerRegistry { constructor(protected overlay: NbOverlayService, protected positionBuilder: NbPositionBuilderService, - protected positionHelper: NbPositionHelper) { + protected positionHelper: NbPositionHelper, + protected cfr: ComponentFactoryResolver) { } get(position: NbGlobalPosition): NbToastContainer { @@ -120,7 +121,7 @@ export class NbToastrContainerRegistry { protected createContainer(position: NbGlobalLogicalPosition): NbToastContainer { const positionStrategy = this.positionBuilder.global().position(position); const ref = this.overlay.create({ positionStrategy }); - const containerRef = ref.attach(new NbComponentPortal(NbToastrContainerComponent)); + const containerRef = ref.attach(new NbComponentPortal(NbToastrContainerComponent, null, null, this.cfr)); return new NbToastContainer(position, containerRef, this.positionHelper); } } diff --git a/src/playground/playground.module.ts b/src/playground/playground.module.ts index 3902b4c524..cae834ff40 100644 --- a/src/playground/playground.module.ts +++ b/src/playground/playground.module.ts @@ -283,7 +283,6 @@ export const NB_MODULES = [ NbCalendarModule, NbCalendarRangeModule, NbCalendarKitModule, - NbToastrModule.forRoot(), NbDialogModule.forRoot(), NbTooltipModule, NbSelectModule, From c6fa5a8375cdfc617d87a34daa9bc737d999c283 Mon Sep 17 00:00:00 2001 From: Nikita Poltoratsky Date: Wed, 3 Oct 2018 08:38:13 +0300 Subject: [PATCH 3/4] fix(dialog): provide componentFactoryResolver --- src/app/app.module.ts | 3 +-- src/framework/theme/components/dialog/dialog.service.ts | 7 ++++--- src/playground/playground.module.ts | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 81fa5475e9..1eae08ed79 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -10,7 +10,7 @@ import { FormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; import { HttpClientModule } from '@angular/common/http'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { NbThemeModule, NbToastrModule } from '@nebular/theme'; +import { NbThemeModule } from '@nebular/theme'; import { NbAppComponent } from './app.component'; import { NbLayoutDirectionToggleComponent } from './layout-direction-toggle/layout-direction-toggle.component'; @@ -24,7 +24,6 @@ import { NbLayoutThemeToggleComponent } from './layout-theme-toggle/layout-theme BrowserAnimationsModule, FormsModule, HttpClientModule, - NbToastrModule.forRoot(), RouterModule.forRoot([ { path: '', diff --git a/src/framework/theme/components/dialog/dialog.service.ts b/src/framework/theme/components/dialog/dialog.service.ts index 6b35d713e9..a8fca7870d 100644 --- a/src/framework/theme/components/dialog/dialog.service.ts +++ b/src/framework/theme/components/dialog/dialog.service.ts @@ -4,7 +4,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. */ -import { Inject, Injectable, Injector, TemplateRef, Type } from '@angular/core'; +import { ComponentFactoryResolver, Inject, Injectable, Injector, TemplateRef, Type } from '@angular/core'; import { fromEvent as observableFromEvent } from 'rxjs'; import { filter } from 'rxjs/operators'; @@ -143,7 +143,8 @@ export class NbDialogService { @Inject(NB_DIALOG_CONFIG) protected globalConfig, protected positionBuilder: NbPositionBuilderService, protected overlay: NbOverlayService, - protected injector: Injector) { + protected injector: Injector, + protected cfr: ComponentFactoryResolver) { } /** @@ -190,7 +191,7 @@ export class NbDialogService { protected createContainer(config: NbDialogConfig, overlayRef: NbOverlayRef): NbDialogContainerComponent { const injector = new NbPortalInjector(this.createInjector(config), new WeakMap([[NbDialogConfig, config]])); - const containerPortal = new NbComponentPortal(NbDialogContainerComponent, null, injector); + const containerPortal = new NbComponentPortal(NbDialogContainerComponent, null, injector, this.cfr); const containerRef = overlayRef.attach(containerPortal); return containerRef.instance; } diff --git a/src/playground/playground.module.ts b/src/playground/playground.module.ts index cae834ff40..3902b4c524 100644 --- a/src/playground/playground.module.ts +++ b/src/playground/playground.module.ts @@ -283,6 +283,7 @@ export const NB_MODULES = [ NbCalendarModule, NbCalendarRangeModule, NbCalendarKitModule, + NbToastrModule.forRoot(), NbDialogModule.forRoot(), NbTooltipModule, NbSelectModule, From 1d7756829a1fee3ce1e52050945a012ddc07d431 Mon Sep 17 00:00:00 2001 From: Nikita Poltoratsky Date: Wed, 3 Oct 2018 10:05:25 +0300 Subject: [PATCH 4/4] fix(toastr): add cfr in spec --- .../theme/components/toastr/toastr.service.spec.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/framework/theme/components/toastr/toastr.service.spec.ts b/src/framework/theme/components/toastr/toastr.service.spec.ts index e7ca7ea0c8..f547347f8b 100644 --- a/src/framework/theme/components/toastr/toastr.service.spec.ts +++ b/src/framework/theme/components/toastr/toastr.service.spec.ts @@ -1,6 +1,9 @@ import { NbToastrContainerRegistry, NbToastrService } from './toastr.service'; import { NbGlobalLogicalPosition, NbGlobalPhysicalPosition } from '../cdk'; import { NbToastStatus } from './model'; +import { TestBed } from '@angular/core/testing'; +import { ComponentFactoryResolver } from '@angular/core'; +import { NbToastrModule } from '@nebular/theme'; describe('toastr-service', () => { @@ -160,7 +163,10 @@ describe('toastr-container-registry', () => { }); beforeEach(() => { - toastrContainerRegistry = new NbToastrContainerRegistry(overlayStub, positionBuilder, positionHelper); + const cfr = TestBed.configureTestingModule({ + imports: [NbToastrModule.forRoot()], + }).get(ComponentFactoryResolver); + toastrContainerRegistry = new NbToastrContainerRegistry(overlayStub, positionBuilder, positionHelper, cfr); }); it('should create new container if not exists for requested position', () => {