Error: StaticInjectorError[BreakpointObserver] No provider for BreakpointObserver
See original GitHub issueBug, feature request, or proposal:
Bug (Regression)
What is the expected behavior?
Ability to use SnackBar
What is the current behavior?
After update to 5.0.0-rc0, initialising MatSnackBar in component constructor causes error:
Error: StaticInjectorError[BreakpointObserver] ... No provider for BreakpointObserver
at runtime
What are the steps to reproduce?
Add reference to
MatSnackBar
in component constructor.
What is the use-case or motivation for changing an existing behavior?
I don’t want to change an existing behavior. I just want it to work like it did before the update.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular 5.0.1
Angular CLI 1.5.0
Material 5.0.0-rc0
Mac OS High Sierra 10.13.1
Typescript 2.4.2
Chrome Version 61.0.3163.100
Is there anything else we should know?
When I add
constructor(...,
...,
private snackbar: MatSnackBar){}
in my component I get this error. If I take out the reference to MatSnackBar, the error goes away.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Angular Material: BreakpointObserver not available from load?
The breakpointObserver is only triggered after a change is observed, but considering it's a fresh load, there is no change yet.
Read more >How To Detect Breakpoints Using the Angular CDK
Learn how to detect viewport size changes or matches against media queries using the BreakpointObserver and MediaMatcher services from the ...
Read more >[Debugging] NullInjectorError: No provider for {Class}!
In this video, you'll learn what the error "NullInjectorError: No provider for {Class}!" means, how to debug it, and prevent it from ...
Read more >Angular CDK's BreakpointObserver - Preston Lamb
The Solution. The solution to this problem is pretty simple, thanks to the Angular CDK. The first step is to install the CDK...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
my fail. I tried:
import {MatSnackBarModule} from "@angular/material/snack-bar";
but I have to:import {MatSnackBarModule} from "@angular/material";
Now, everything works fine. Thank you@chriscurnow I had the same problem just now. It was caused by a missing MatSnackbarModule import. I don’t know why, but with Angular 4.x and Angular Material 2.0.0-beta it worked (it probably shouldn’t have). After the upgrade to Angular 5.0.1 and Material 5.0.0-rc0 I had the same error message.
Adding the following import solved it: https://github.com/julianobrasil/material2-test/blob/master/src/app/app.module.ts#L35