title: How to inject snackBarRef into a component with openFromComponent
body: <p>The latest <a href="https://material.angular.io/components/snack-bar/overview" rel="noreferrer">Material documentation</a> says the following..</p>
  
  <blockquote>
    <p>If you want to close a custom snack-bar that was opened via openFromComponent, from within the component itself, you can inject the MatSnackBarRef.</p>
  </blockquote>
  
  <p>but they don't show you <em>how</em> to do it.</p>
  
  <p>In their example, they nest a component within the same .ts file as the calling module, and they <em>don't</em> show the ref being passed in. But since I want to use a more centralized approach, I have created a new module using...</p>
  
  <pre><code>ng g component components/snackbar
  </code></pre>
  
  <p>This way, I should be able to pass in @Input to render different html  depending on need. This would further allow for things like branding, multiple buttons, and for html buttons to dismiss the snackbar… as long as they have access to a ref!</p>
  
  <p>My calling .ts has the following...</p>
  
  <pre><code>var snackBarRef : any;
  snackBarRef = this.snackBar.openFromComponent(SnackbarComponent, {data : snackBarRef});
  </code></pre>
  
  <p>the component .ts has the following constructor...</p>
  
  <pre><code>constructor(public snackBar: MatSnackBar, @Inject(MAT_SNACK_BAR_DATA) public data: any) { }
  </code></pre>
  
  <p>My expectations are that I could then create a function in the component that could act upon snackBarRef.dismiss(); as needed. However, when I run the app, I get the following error...</p>
  
  <pre><code>Uncaught (in promise): Error: StaticInjectorError(AppModule)[SnackbarComponent -&gt; InjectionToken MatSnackBarData]: 
    StaticInjectorError(Platform: core)[SnackbarComponent -&gt; InjectionToken MatSnackBarData]
  </code></pre>
  
  <p>Just to make sure I had the plumbing right, I swapped out {data : snackBarRef} to {data : 0}. By doing that, I don't see any errors and I can use the data value of 0 for other things, but of course I also don't have a handle on the ref to use locally.</p>
  
  <p>Is there another way to pass the snackBarRef into the component other than using the data section of the openFromComponent? or, alternatively, is there a way to pass the ref through the data section without causing the error?</p>