title: Returning Data from MdDialog in Angular Material 2
body: <p>I am using a MdDialogModule to show a Dialog window with an input field in it. The Modal is opening fine and I am able to enter text into input field and submit, but on clicking the Submit button, I want the data in the Input form to be returned to the Main Component that called the Dialog component and also close the Dialog.</p>
  
  <p>How do I do this? I am able to pass data to MdDialog component, but didn't find any resource on how to return data to component from MdDialogComponent.</p>
  
  <p>My Dialog component code looks like this</p>
  
  <pre><code>import { Component, OnInit, InjectionToken, Inject } from '@angular/core';
  import { MD_DIALOG_DATA, MdDialogRef } from "@angular/material";
  
  @Component({
    selector: 'app-add-book',
    templateUrl: './add-book.component.html',
    styleUrls: ['./add-book.component.css']
  })
  export class AddBookComponent {
  
    constructor() { }
  
  }
  </code></pre>
  
  <p>and the method in main component calling the dialog box looks like this. No response is being returned now, it returns Undefined as I haven't figured it out yet.</p>
  
  <pre><code>openCreateDialog() {
      let dialogRef = this.dialog.open(AddBookComponent)
        .afterClosed()
        .subscribe(response =&gt; {
          console.log(response);
        });
    }
  </code></pre>