question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: StaticInjectorError[BreakpointObserver] No provider for BreakpointObserver

See original GitHub issue

Bug, 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:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

20reactions
igor90007commented, Nov 14, 2017

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

12reactions
cyber-simoncommented, Nov 14, 2017

@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

NgModule({
...
  ],
  imports: [
...
    MatSnackBarModule,
...
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found