Skip to content

Commit

Permalink
fix(modal): should fix 'no provider for ...' exception
Browse files Browse the repository at this point in the history
  • Loading branch information
valorkin authored and Gxerxes committed Oct 28, 2016
1 parent 7e976ba commit 6a28369
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions components/utils/components-helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ export class ComponentsHelper {
* ```
* @returns {ViewContainerRef} - application root view component ref
*/
public getRootViewContainerRef(injector:Injector):ViewContainerRef {
public getRootViewContainerRef(_injector:Injector):ViewContainerRef {
// The only way for now (by @mhevery)
// https://github.com/angular/angular/issues/6446#issuecomment-173459525
// this is a class of application bootstrap component (like my-app)
const classOfRootComponent = this.applicationRef.componentTypes[0];
// this is an instance of application bootstrap component
const appInstance = injector.get(classOfRootComponent);
let appInstance:any;
let injector:any = _injector as any;
while (!appInstance) {
appInstance = injector.get(classOfRootComponent, false);
if (!appInstance && injector.parentInjector) {
injector = injector.parentInjector;
}
}
return appInstance.viewContainerRef;
}

Expand Down

0 comments on commit 6a28369

Please sign in to comment.