Angular 2 Material MdSnackBar no Provider

Florian picture Florian · Aug 2, 2017 · Viewed 10.8k times · Source

I want a simple Snackbar popping up on the click of a button. But I always get the error:

ERROR Error: No provider for MdSnackBar! at injectionError (core.es5.js:1169) at noProviderError (core.es5.js:1207

import {MdSnackBar} from '@angular/material';
constructor(public snackBar: MdSnackBar){
        this.snackBar.open('hello')
    }

Answer

Meet Dave picture Meet Dave · Aug 23, 2017

Import MdSnackBarModule then add MdSnackBarModule inside your imports in the app.module.ts file