Skip to content

Commit

Permalink
refactor(dynamicComponentLoader): remove deprecated dynamic component…
Browse files Browse the repository at this point in the history
… loader
  • Loading branch information
Matt Lewis committed Jun 16, 2016
1 parent 36f315f commit 4339bd7
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/confirm.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import {
EventEmitter,
HostListener,
ViewContainerRef,
DynamicComponentLoader,
ComponentRef,
OnDestroy,
ElementRef,
OnChanges,
OnInit,
ReflectiveInjector,
ResolvedReflectiveProvider
ResolvedReflectiveProvider,
ComponentResolver,
Injector
} from '@angular/core';
import {ConfirmPopover} from './confirmPopover.component';
import {ConfirmOptions, PopoverConfirmOptions} from './confirmOptions.provider';
Expand Down Expand Up @@ -134,9 +135,9 @@ export class Confirm implements OnDestroy, OnChanges, OnInit {
*/
constructor(
private viewContainerRef: ViewContainerRef,
private loader: DynamicComponentLoader,
private elm: ElementRef,
private defaultOptions: ConfirmOptions
private defaultOptions: ConfirmOptions,
private componentResolver: ComponentResolver
) {}

/**
Expand Down Expand Up @@ -215,17 +216,19 @@ export class Confirm implements OnDestroy, OnChanges, OnInit {
}
});

const binding: ResolvedReflectiveProvider[] = ReflectiveInjector.resolve([{
provide: PopoverConfirmOptions,
useValue: options
}]);

this.popover = this.loader
.loadNextToLocation(ConfirmPopover, this.viewContainerRef, binding)
.then((popover: ComponentRef<ConfirmPopover>) => {
this.isOpenChange.emit(true);
return popover;
});
this.popover = this.componentResolver.resolveComponent(ConfirmPopover).then(componentFactory => {
const binding: ResolvedReflectiveProvider[] = ReflectiveInjector.resolve([{
provide: PopoverConfirmOptions,
useValue: options
}]);
const contextInjector: Injector = this.viewContainerRef.parentInjector;
const childInjector: Injector = ReflectiveInjector.fromResolvedProviders(binding, contextInjector);
const popover: ComponentRef<ConfirmPopover> =
this.viewContainerRef.createComponent(componentFactory, this.viewContainerRef.length, childInjector);
this.isOpenChange.emit(true);
return popover;
});

}
}

Expand Down

0 comments on commit 4339bd7

Please sign in to comment.