Skip to content

Commit

Permalink
fix(modal): should fix 'no provider for ...' exception
Browse files Browse the repository at this point in the history
should fix #854, fix #951
  • Loading branch information
valorkin committed Sep 14, 2016
1 parent 8483615 commit 4c3e4c9
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 4c3e4c9

Please sign in to comment.