Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(component helper): remove hack get app root #951

Closed
ctrl-brk opened this issue Sep 11, 2016 · 6 comments
Closed

fix(component helper): remove hack get app root #951

ctrl-brk opened this issue Sep 11, 2016 · 6 comments

Comments

@ctrl-brk
Copy link

RC6. Using modal component. Was working fine until I separated the application into modules. Now in lazy loaded module when I try to call .show() method I'm getting an error: No provider for AppComponent!

As you may guessed the AppComponent is my main/default component in the app root module. How does this modal even know about AppComponent existence?

On StackOverflow: http://stackoverflow.com/questions/39431567/angular2-ng2-bootstrap-in-lazy-loaded-module-needs-app-root-module-for-some-rea

@valorkin
Copy link
Member

It was a hack to get root app scope, and seems it is not always working now ;(

@valorkin valorkin changed the title ng2-bootstrap in lazy loaded module needs app root module for some reason fix(component helper): remove hack get app root Sep 12, 2016
@valorkin
Copy link
Member

valorkin commented Sep 14, 2016

@ctrl-brk can you share a repo(sample) so I can test a fix?

@marcuskrahl
Copy link

marcuskrahl commented Sep 15, 2016

@valorkin The fix does not work for me. The injector in ComponentHelper is of type ElementInjector.

injector.get(classOfRootComponent, false); returns false because the AppComponent is not found. Since ElementInjector does not have a parent attribute, this results in an endless while loop.

Maybe there is a new way to access root components in a lazy loaded module. I tested the code with angular 2.0.0 by the way

Trying to access the AppComponent directly in the constructor of the hosting component throws an error as well. Might be an angular bug or design choice after all:

export class ComponentWithModal {
    constructor(private appComponent: AppComponent) {
       //throws  No provider for AppComponent!
   }
}

@marcuskrahl
Copy link

@valorkin I created a repository to reproduce the bug. The page freezes when trying to open a modal. It works fine if the corresponding module is not lazy loaded.

https://github.com/marcuskrahl/ng2-bootstrap-951

@valorkin
Copy link
Member

Please try 1.1.5, it is fixed

jtomaszewski pushed a commit to jtomaszewski/ng2-bootstrap that referenced this issue Oct 22, 2016
Gxerxes pushed a commit to Gxerxes/ng2-bootstrap that referenced this issue Oct 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants