title: angular 2: prevent user to click outside the modal dialog
body: <p>I want to prevent from the user to click outside the modal dialog and he only can press on the button to exit from the dialog. how can I do that?</p>
  
  <p>dialog.component.ts</p>
  
  <pre><code>ngOnInit() {
  
  const dialogRef = this.dialog.open(DialogResultComponent);
  dialogRef.afterClosed().subscribe(result =&gt; {
    console.log(result);
  });
  </code></pre>
  
  <p>}</p>
  
  <p>dialog-result.component.ts</p>
  
  <pre><code>    import { Component, OnInit } from '@angular/core';
  import { MdDialog, MdDialogRef } from '@angular/material';
  import { FormGroup,FormControl,Validators,FormBuilder,  } from '@angular/forms';
  
  
  
  @Component({
    selector: 'app-dialog-result',
    templateUrl: './dialog-result.component.html',
  })
  
  export class DialogResultComponent {
  
  
    form: FormGroup;
    name = new FormControl('',Validators.required);
    width = new FormControl('',Validators.required);
    height = new FormControl('',Validators.required);
    constructor(public dialogRef: MdDialogRef&lt;DialogResultComponent&gt;,private fb: FormBuilder) {
  
    }
  
    ngOnInit() {
    this.form = this.fb.group({
        'name' :this.name,
        'width':   this.width,
        'height':  this.height,
      });
  }
  
    saveData(){
      console.log(this.name.value);
      this.dialogRef.close({name:this.name.value,width:this.width.value,height:this.height.value});
    }
  }
  </code></pre>
  
  <p>what I tried to do is:
  <strong>dialog-result.component.html</strong></p>
  
  <pre><code>       &lt;div&gt;
     &lt;form [formGroup]="form"&gt;
       &lt;h3&gt;MineSweeperwix&lt;/h3&gt;
        &lt;div class="mdl-dialog__content"&gt;
                  &lt;p&gt;&lt;mdl-textfield type="text" label="name" ([ngModel])="name" floating-label autofocus&gt;&lt;/mdl-textfield&gt;&lt;/p&gt;
                  &lt;mdl-textfield type="number" formControlName="width"  label="width"   floating-label autofocus&gt;&lt;/mdl-textfield&gt;
                 &lt;mdl-textfield type="number" formControlName="height" label="height" floating-label autofocus  error-msg="'Please provide a correct email!'"&gt;&lt;/mdl-textfield&gt;
        &lt;/div&gt;
        &lt;div class="mdl-dialog__actions"&gt;
          &lt;button mdl-button (click)="saveData()" mdl-button-type="raised" mdl-colored="primary" mdl-ripple [disabled]="!form.valid"&gt;Save&lt;/button&gt;
          &lt;button mdl-button (click)="dialogRef.close(dd)" mdl-button-type="raised" mdl-ripple&gt;Cancel&lt;/button&gt;
        &lt;/div&gt;
     &lt;/form&gt;
     &lt;/div&gt;
  </code></pre>
  
  <p>dialog-result.component.cs</p>
  
  <pre><code>    div.modal-backdrop {
      position: fixed;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      z-index: 100; /* less than your dialog but greater than the rest of your app */
      /* optional: */
      background: black;
      opacity: 0.2;
  }
  </code></pre>