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

No provider for Overlay! StaticInjectorError(AppModule)[MatMenuTrigger -> Overlay]: #10820

Closed
elvisbegovic opened this issue Apr 12, 2018 · 44 comments · Fixed by #11213
Closed
Assignees
Labels
P2 The issue is important to a large percentage of users, with a workaround

Comments

@elvisbegovic
Copy link

Bug, feature request, or proposal:

bug

What are the steps to reproduce?

I update from angular 5.x and cli 1.7.x and rxjs 5.x to v6rc.x
I only update in my module this MatMenuModule and use it like:

<div *ngFor="let item of data">
  <button mat-icon-button [matMenuTriggerFor]="appMenu"></button>
  <mat-menu #appMenu="matMenu" [overlapTrigger]="false"
            class="slds-dropdown slds-dropdown_left slds-dropdown_actions">
    <ul class="slds-dropdown__list" role="menu">
      <li (click)="onClickCreerPO.emit({bail:item, nature:'Rent'})">
        <a href="javascript:void(0);">PO Loyer</a>
      </li>
      <li (click)="onClickCreerPO.emit({bail:item, nature:'AddedRent'})">
        <a href="javascript:void(0);">PO Surplus</a>
      </li>
    </ul>
  </mat-menu>
</div>

Before

It was working before update.

Current

image

@cyrilletuzi
Copy link
Contributor

cyrilletuzi commented Apr 20, 2018

Same error. It seems like one Material component now has a dependency to CDK OverlayModule. Would be a breaking change, but it's not documented in the changelog. Using RC12.

@crisbeto
Copy link
Member

crisbeto commented May 1, 2018

@cyrilletuzi the menu module has always had a dependency on the OverlayModule, I don't think anything has changed recently.

@istiti are you able to reproduce the error in a Stackblitz?

@cyrilletuzi
Copy link
Contributor

For me it's not the menu, I don't use this one. But I just upgraded from Material 5 to 6, without any change in my app, and no I have the same error, needing OverlayModule. So at least one of my Material module has this new dependency.

@cyrilletuzi
Copy link
Contributor

cyrilletuzi commented May 1, 2018

For me it's MatAutocomplete which now need OverlayModule (the error mentionsMatAutocompleteTrigger). Wasn't needed in v5 and not mentioned in documentation, no change in app.

@crisbeto
Copy link
Member

crisbeto commented May 1, 2018

The autocomplete module has also had the OverlayModule import for a long time now. We haven't even touched that line in more than six months.

@cyrilletuzi
Copy link
Contributor

Then there really is an issue: I have to manually add the OverlayModule in my AppModule for the mat-autocomplete to continue to work in v6, and that doesn't seem normal if it's already imported.

@cyrilletuzi
Copy link
Contributor

cyrilletuzi commented May 1, 2018

After some tests, it appears it's only happen in v6 when the module where MatAutocomplete is used is lazy-loaded.

@elvisbegovic
Copy link
Author

Breaking change to my code or i used it wrongly but was working well in v5 simply adding MatMenuModule in certain lazymodule yes 😞

@crisbeto
Copy link
Member

crisbeto commented May 2, 2018

This sounds like a tooling issue. @cyrilletuzi can you double-check that both Material and all other @angular/* packages are on the same major version?

@cyrilletuzi
Copy link
Contributor

cyrilletuzi commented May 2, 2018

@crisbeto Yep, everything (Angular / Material / CLI) is in v6 very last RC, and issue reproduced from scratch.

@ghost
Copy link

ghost commented May 3, 2018

I've the same issue with the MatMenuTrigger.
Is there any workaround, which can make it work until the problem is solved?

@bardiel
Copy link

bardiel commented May 3, 2018

I also fixed it by importing OverlayModule in my app.module.ts.
Importing OverlayModule in lazy-loaded modules by the Router would't work.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";

import { OverlayModule } from "@angular/cdk/overlay";

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    OverlayModule,
    AppRoutingModule,
  ],
  providers: [],
  bootstrap: [
    AppComponent,
  ],
})
export class AppModule { }

@bardiel
Copy link

bardiel commented May 3, 2018

Btw, this happened to me in a brand new project generated yesterday with all @angular/*@next deps.

Angular CLI: 6.0.0-rc.9
Node: 8.11.1
OS: linux x64
Angular: 6.0.0-rc.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.5.12
@angular-devkit/build-angular     0.5.12
@angular-devkit/build-optimizer   0.5.12
@angular-devkit/core              0.5.12
@angular-devkit/schematics        0.5.12
@angular/cdk                      6.0.0-rc.14
@angular/cli                      6.0.0-rc.9
@angular/flex-layout              6.0.0-beta.15
@angular/material                 6.0.0-rc.14
@ngtools/webpack                  6.0.0-rc.10
@schematics/angular               0.5.12
@schematics/update                0.5.12
rxjs                              6.0.0
typescript                        2.7.2
webpack                           4.6.0

@yokots
Copy link

yokots commented May 4, 2018

when i import the overlay module in a lazy loading module it also dosen't work. and jsut import the OVERLAY_PROVIDERS is ok. like this

import { OverlayModule } from '@angular/cdk/overlay';

@NgModule({
  imports: [OverlayModule]
})
export class NoLazyLoadingModule { }

@yushihui
Copy link

yushihui commented May 4, 2018

Today I updated to angular 6 have the same issue,

ERROR Error: StaticInjectorError(WzzModule)[MatMenuTrigger -> Overlay]:
StaticInjectorError(Platform: core)[MatMenuTrigger -> Overlay]:
NullInjectorError: No provider for Overlay!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:979)
at resolveToken (core.js:1232)
at tryResolveToken (core.js:1182)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1077)
at resolveToken (core.js:1232)
at tryResolveToken (core.js:1182)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1077)
at resolveNgModuleDep (core.js:9238)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:9919)
at inject (core.js:1334)

@yushihui
Copy link

yushihui commented May 4, 2018

@yokots
I tried your fix, but it does not work for me

@yushihui
Copy link

yushihui commented May 4, 2018

when I add
import {OverlayModule} from '@angular/cdk/overlay';
to my root module
it works

@keatkeat87
Copy link

keatkeat87 commented May 5, 2018

image
i guess this cause Overlay must provide in root injector.

@yokots
Copy link

yokots commented May 5, 2018

@yushihui The OVERLAY_PROVIDERS was deprecated. Just use OverlayModule.

@cyrilletuzi
Copy link
Contributor

What's happening is quite strange: modules using Overlay (like MatMenu or MatAutocomplete) are already importing OverlayModule. So, lazy-loading or not, it should work.

The fact that when lazy-loading a module with MatMenu or MatAutocomplete, we have this error, means that something outside the module is using Overlay, which doesn't seem normal.

@Eddygn
Copy link

Eddygn commented May 6, 2018

Having similar issue due to [matTooltip].
Project was upgraded to 6 (release)

ERROR Error: StaticInjectorError(AppModule)[CdkConnectedOverlay -> Overlay]: 
  StaticInjectorError(Platform: core)[CdkConnectedOverlay -> Overlay]: 
    NullInjectorError: No provider for Overlay!
    at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get

Hope it helps

@yokots
Copy link

yokots commented May 6, 2018

@crisbeto here is an example in Stackblitz

@Tyler-V
Copy link

Tyler-V commented May 7, 2018

What about if importing OverlayModule at the app.module.ts isn't an option? I am shipping a component as a library that uses material.

Importing OverlayModule at the library.module does not resolve the issue, only if I import it at the app.module of the project that uses my library... this would require the user to perform additional setup instead of just being able to import my library and use it right away,

Is there anyway around this?

StaticInjectorError(Platform: core)[MatMenuTrigger -> Overlay]: 
    NullInjectorError: No provider for Overlay!

crisbeto added a commit to crisbeto/material2 that referenced this issue May 7, 2018
…loaded modules

Fixes injection errors being thrown by the overlay-based providers that have injection tokens for the default scroll strategy. The error comes from the fact that the scroll strategies were being provided at the root, whereas the `Overlay` provider was provided normally, causing it to be missing when a module is lazy-loaded.

Fixes angular#10820.
@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround has pr labels May 7, 2018
crisbeto added a commit to crisbeto/material2 that referenced this issue May 8, 2018
…loaded modules

Fixes injection errors being thrown by the overlay-based providers that have injection tokens for the default scroll strategy. The error comes from the fact that the scroll strategies were being provided at the root, whereas the `Overlay` provider was provided normally, causing it to be missing when a module is lazy-loaded.

Fixes angular#10820.
crisbeto added a commit to crisbeto/material2 that referenced this issue May 8, 2018
…loaded modules

Fixes injection errors being thrown by the overlay-based providers that have injection tokens for the default scroll strategy. The error comes from the fact that the scroll strategies were being provided at the root, whereas the `Overlay` provider was provided normally, causing it to be missing when a module is lazy-loaded.

Fixes angular#10820.
@AnthonyNahas
Copy link

I am facing the same problem with matToolTip -->

core.js:1601 ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[MatTooltip -> Overlay]: 
  StaticInjectorError(Platform: core)[MatTooltip -> Overlay]: 
    NullInjectorError: No provider for Overlay!
Error: StaticInjectorError(AppModule)[MatTooltip -> Overlay]: 
  StaticInjectorError(Platform: core)[MatTooltip -> Overlay]: 
    NullInjectorError: No provider for Overlay!
    at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:979)
    at resolveToken (core.js:1232)
    at tryResolveToken (core.js:1182)
    at 

Im getting the error since I updated angular from v5 to v6

@CharlBest
Copy link

Yes this is also breaking for me after updating to v6.

ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[MatTooltip -> Overlay]:
StaticInjectorError(Platform: core)[MatTooltip -> Overlay]:
NullInjectorError: No provider for Overlay!
Error: StaticInjectorError(AppModule)[MatTooltip -> Overlay]:
StaticInjectorError(Platform: core)[MatTooltip -> Overlay]:
NullInjectorError: No provider for Overlay!

@renatop7
Copy link

For everyone having problems with the NullInjectorError: No provider for Overlay! when trying to lazy load, just try to add OverlayModule to app.module imports, or your root module, for me it worked like a charm.

It's a temporary fix until they update the code...

@Tyler-V
Copy link

Tyler-V commented May 10, 2018

@renatop7 I too saw that referenced in another issue however that doesn't work for me inside a library, importing it inside the project's module or app module results in the same error.

@renatop7
Copy link

@Tyler-V Yeah, it seems another problem.
What you could do is try to implement a forRoot() method in your library, and add the Overlay provider in there.
I'm not sure if this would help you, and I can't test it, but it was something that came to mind when I read your response.

@AnthonyNahas
Copy link

@renatop7 you have right! The only way to get that thing working is to import OverlayModule
in the app component (the root) module and not in the lazy loaded module..... 🍰

crisbeto added a commit to crisbeto/material2 that referenced this issue May 11, 2018
…loaded modules

Fixes injection errors being thrown by the overlay-based providers that have injection tokens for the default scroll strategy. The error comes from the fact that the scroll strategies were being provided at the root, whereas the `Overlay` provider was provided normally, causing it to be missing when a module is lazy-loaded.

Fixes angular#10820.
crisbeto added a commit to crisbeto/material2 that referenced this issue May 15, 2018
…loaded modules

Fixes injection errors being thrown by the overlay-based providers that have injection tokens for the default scroll strategy. The error comes from the fact that the scroll strategies were being provided at the root, whereas the `Overlay` provider was provided normally, causing it to be missing when a module is lazy-loaded.

Fixes angular#10820.
crisbeto added a commit to crisbeto/material2 that referenced this issue May 16, 2018
…loaded modules

Fixes injection errors being thrown by the overlay-based providers that have injection tokens for the default scroll strategy. The error comes from the fact that the scroll strategies were being provided at the root, whereas the `Overlay` provider was provided normally, causing it to be missing when a module is lazy-loaded.

Fixes angular#10820.
tinayuangao pushed a commit that referenced this issue May 16, 2018
…loaded modules (#11213)

Fixes injection errors being thrown by the overlay-based providers that have injection tokens for the default scroll strategy. The error comes from the fact that the scroll strategies were being provided at the root, whereas the `Overlay` provider was provided normally, causing it to be missing when a module is lazy-loaded.

Fixes #10820.
@matheusdavidson
Copy link

Same problem with v6 and Material Datepicker.
Importing OverlayModule into app.module(must be loaded here) solved the problem.

@cgatian
Copy link

cgatian commented May 21, 2018

@jelbourn It would be nice when regressions are found if there was a milestone/timeline created to provide insight on when merged issues would be released.

@wangyud
Copy link

wangyud commented Jun 13, 2018

@yushihui @matheusdavidson I do this . but it doesn't work

@fazpu
Copy link

fazpu commented Jun 18, 2018

Hi, I had the same problem.

Turned out it was caused by importing @import '~bootstrap/scss/bootstrap'; in styles.scss

I ended up importing only

@import '~bootstrap/scss/bootstrap-grid';
@import '~bootstrap/scss/mixins';
@import '~bootstrap/scss/utilities';

This was sufficient for my needs and the error went away.

@idshdx
Copy link

idshdx commented Aug 7, 2018

The quickfix does not work for a NgModule created with the TestBed..

TestBed.configureTestingModule({
      providers: [
        UiEffects,
        // MatDialogModule,
        OverlayModule,
        // MatDialog,
        DialogService,
       .....

Error: StaticInjectorError(DynamicTestModule)[MatDialog -> Overlay]:

@alanxone
Copy link

alanxone commented Aug 24, 2018

Just wanna check if the issue fixed in the latest version 6.4.6, because our apps still encounter the same problem after upgrading to 6.4.6.

@michaelspeed
Copy link

i am still getting this error, although i have added OverlayModule in the AppModule.
i even tried adding them to all the LazyLoad Modules, still no fix

@Maryannah
Copy link

Hello,

Although I am late to the post, I am facing the same issue.

I have created a showcase project for a library I'm coding. When using a custom overlay service that I wrote, I faced the error.

Simply providing my service into the module, instead of using providedIn: root solved the issue.

I'm posting that just in case someone encounters the same issue in the same case.

Sorry I bothered you all !

@SarveshDeshmukh
Copy link

Hello,

Although I am late to the post, I am facing the same issue.

I have created a showcase project for a library I'm coding. When using a custom overlay service that I wrote, I faced the error.

Simply providing my service into the module, instead of using providedIn: root solved the issue.

I'm posting that just in case someone encounters the same issue in the same case.

Sorry I bothered you all !

This worked for me!

@deepthan
Copy link

deepthan commented Apr 4, 2019

If you use ng-zorro-antd, you can try it with the following versions:

 "dependencies": {
    "@angular/animations": "~7.0.0",
    "@angular/common": "~7.0.0",
    "@angular/compiler": "~7.0.0",
    "@angular/core": "~7.0.0",
    "@angular/forms": "~7.0.0",
    "@angular/http": "~7.0.0",
    "@angular/platform-browser": "~7.0.0",
    "@angular/platform-browser-dynamic": "~7.0.0",
    "@angular/router": "~7.0.0",
    "core-js": "^2.6.3",
    "ng-zorro-antd": "^7.0.3",
    "zone.js": "~0.8.29"
 },
 "devDependencies": {
    "@angular-devkit/build-angular": "0.12.3",
    "@angular/cli": "~7.3.6",
    "@angular/compiler-cli": "^7.2.9",
    "@angular/language-service": "^7.2.9",
    "@angularclass/hmr": "^2.1.3",
    "@types/jasmine": "~3.3.12",
    "@types/jasminewd2": "~2.0.6",
    "@types/node": "~11.11.4",
    "codelyzer": "~5.0.0-beta.1",
    "jasmine-core": "~3.3.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.5",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.2",
    "ts-node": "~8.0.3",
    "tslint": "~5.14.0",
    "typescript": "3.2.4"
  }

@vanessaLatefa
Copy link

vanessaLatefa commented Apr 16, 2019

Hello, Im also facing this error, and I dont know how to fix it..
I am lazy loading my log in from a home module..
Login has Auth service and Auth guard.
Please help!

[Error] ERROR – Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[LoginComponent -> MatSnackBar]:
StaticInjectorError(Platform: core)[LoginComponent -> MatSnackBar]:
NullInjectorError: No provider for MatSnackBar!
get@http://localhost:4200/vendor.js:69847:28
resolveToken@http://localhost:4200/vendor.js:70092:27
tryResolveToken@http://localhost:4200/vendor.js:70036:28

@lppedd
Copy link

lppedd commented Jun 11, 2019

Same problem after updating to Angular 8.

@billbarni
Copy link

Same problem. Angular 7.2.

@Vasu6916
Copy link

import { Overlay } from '@angular/cdk/overlay' in the spec file
This fixed the issue for me

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet