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

6.0.5 errors due to BrowserModule #43

Closed
achimha opened this issue Apr 30, 2017 · 6 comments
Closed

6.0.5 errors due to BrowserModule #43

achimha opened this issue Apr 30, 2017 · 6 comments

Comments

@achimha
Copy link

achimha commented Apr 30, 2017

With 6.0.5 I get an error on my lazily loaded modules using the ClipboardModule:

Uncaught (in promise): Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.

I do not load ClipboardModule in my main bundle but only in lazily loaded modules using

imports: [
  ClipboardModule.forRoot()
]

The problem is that it imports BrowserModule, it should import CommonModule instead.

@achimha
Copy link
Author

achimha commented Apr 30, 2017

A better approach for the singleton pattern can be found here: angular/angular#13854

@maxisam
Copy link
Owner

maxisam commented May 1, 2017

I just released 6.0.6 address this issue by using CommonModule

However, when I tried the pattern you suggest, I'm kinda stuck. Please check this branch

I think by using that pattern, somehow DI doesn't really work anymore.

@achimha
Copy link
Author

achimha commented May 1, 2017

Thanks for the fix.

I haven't had a chance to test your tree. The code looks correct to me. What exactly happens? I have used the pattern successfully in one of my modules.

@maxisam
Copy link
Owner

maxisam commented May 1, 2017

I know. I went thru that one. For some reasons, clipboard service doesn't get WindowSrv instance.
In your case, ngZone should have been created before loading the module. But in this case, WindowSrv is create at the same time.
But I tried new WindowSrv() and it didn't work either.

maxisam added a commit that referenced this issue May 2, 2017
### Feature: 
base on #43, (pull request #46) now it uses a new singleton pattern instead of forRoot pattern.

### Breaking Changes:

Remove forRoot() in imports.

`imports: [ClipboardModule]`
@maxisam
Copy link
Owner

maxisam commented May 2, 2017

I figured it out. I forgot to put windowSrv in providers. duh ! Please try 7.0.1

@maxisam maxisam closed this as completed May 2, 2017
@achimha
Copy link
Author

achimha commented May 2, 2017

Working fine, thank you! Much better now 😄 I hope one day Angular will provide a more convenient pattern for this use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants