Skip to content

Commit

Permalink
fix(theme): fix overlay components providers import (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
tibing-old-email authored and nnixaa committed Oct 3, 2018
1 parent e218df4 commit 843a6c6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
12 changes: 10 additions & 2 deletions src/framework/theme/components/cdk/overlay/overlay-container.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Component,
ComponentFactoryResolver,
ComponentRef,
EmbeddedViewRef,
HostBinding,
Expand All @@ -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;
Expand Down Expand Up @@ -54,7 +55,8 @@ export class NbOverlayContainerComponent {

attachComponentPortal<T>(portal: NbComponentPortal<T>): ComponentRef<T> {
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<C>(portal: NbTemplatePortal<C>): EmbeddedViewRef<C> {
Expand All @@ -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],
]));
}
}
7 changes: 4 additions & 3 deletions src/framework/theme/components/dialog/dialog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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) {
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 7 additions & 1 deletion src/framework/theme/components/toastr/toastr.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
7 changes: 4 additions & 3 deletions src/framework/theme/components/toastr/toastr.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/playground/playground.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export const NB_MODULES = [
NbMenuModule.forRoot(),
NbActionsModule,
NbSearchModule,
NbThemeModule.forRoot({ name: 'default' }),
NbThemeModule,
NbTabsetModule,
NbRouteTabsetModule,
NbUserModule,
Expand Down

0 comments on commit 843a6c6

Please sign in to comment.