title: Validate form in dialog Angular
body: <p>I have using material dialogs for Angular, where I need to enter title and select approve or reject variant.</p>
  
  <p>Here code of the component</p>
  
  <pre><code>  import {Component, Inject, OnInit} from '@angular/core';
  import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material";
  import {FormBuilder, Validators, FormGroup} from "@angular/forms";
  import { Payment } from '../payments/payment';
  
  
  @Component({
      selector: 'editing-dialog',
      templateUrl: './editing-dialog.component.html',
      styleUrls: ['./editing-dialog.component.scss']
  })
  export class EditingDialogComponent implements OnInit {
      form: FormGroup;
      reason:String;
      id: Number;
      statusdescription: String;
  
      constructor(
          fb: FormBuilder,
          private dialogRef: MatDialogRef&lt;EditingDialogComponent&gt;,
          @Inject(MAT_DIALOG_DATA) data:Payment) {
              this.reason = data.Reason;
              this.id  = data.Id;
              this.statusdescription = data.StatusDescription;
              this.form = fb.group({
                  reason: [this.reason, Validators.maxLength(5)],
                  id: this.id,
                  status: status
              });
      }
  
      ngOnInit() {
  
      }
      save() {
          this.dialogRef.close(this.form.value);
      }
  
      close() {
          this.dialogRef.close();
      }
  }
  </code></pre>
  
  <p>And here is html of this component</p>
  
  <pre><code>&lt;h2&gt;{{description}}&lt;/h2&gt;
  
  &lt;mat-dialog-content [formGroup]="form"&gt;
  
      &lt;mat-form-field&gt;
  
          &lt;input matInput required placeholder="Payment Reason" formControlName="reason" value="{{reason}}"&gt;
  
  
      &lt;/mat-form-field&gt;
      &lt;mat-radio-group formControlName="status"&gt;
          &lt;mat-radio-button  value="Approved"&gt;Approved&lt;/mat-radio-button&gt;
          &lt;mat-radio-button value="Rejected"&gt;Rejected&lt;/mat-radio-button&gt;
        &lt;/mat-radio-group&gt;
  &lt;/mat-dialog-content&gt;
  
  &lt;mat-dialog-actions&gt;
  
      &lt;button class="mat-raised-button" (click)="save()"&gt;
          Ok
      &lt;/button&gt;
  
  
  
      &lt;button class="mat-raised-button"
              (click)="close()"&gt;
          Close
      &lt;/button&gt;
  
  &lt;/mat-dialog-actions&gt;
  </code></pre>
  
  <p>I need to make validation if input is filled and if one of radio buttons selected when I click <code>ok</code> button. Now I have required validation for input. </p>
  
  <p>How I can do this corretly?</p>
  
  <p>Thanks for help.</p>