title: How to do validation with mat-checkbox?
body: <p>I would like to know how to check if the checkbox was selected, if it was not selected, an error message will appear for the user.
  I managed to put the error message but not to able to use it along with the rest of the form.
  can you help me?
  Here's what I have to do.</p>
  
  <pre><code>&lt;mat-checkbox class="hcs-full-width" [formControl]="termsFormControl"&gt; Aceite os termos de uso
  
  &lt;/mat-checkbox&gt;
  &lt;mat-error *ngIf="termsFormControl.hasError('required')"&gt;
      Termo é
      &lt;strong&gt;requirido&lt;/strong&gt;
  &lt;/mat-error&gt;
  </code></pre>
  
  <p>.ts</p>
  
  <pre><code>export class AppComponent implements OnInit {
  
    private subscription: Subscription;
    uri: string;
    ssid: string;
    sessiondId: string;
    ip: string;
    mac: string;
    ufi: string;
    mgmtBaseUrl: string;
    clientRedirectUrl: string;
    req: string;
    userName: string;
    hmac: string;
  
    name: string;
    email: string;
  
    constructor(@Inject(DOCUMENT) private document: any, private route: ActivatedRoute) {
    }
  
    ngOnInit() {
      this.route.queryParams
        .filter(params =&gt; params.mac)
        .subscribe(params =&gt; {
          console.log(params);
  
          this.ssid = params.ssid;
          this.sessiondId = params.sessionId;
          this.ip = params.ip;
          this.mac = params.mac;
          this.ufi = params.ufi;
          this.mgmtBaseUrl = params.mgmtBaseUrl;
          this.clientRedirectUrl = params.clientRedirectUrl;
          this.req = params.req;
          this.hmac = params.hmac;
        });
        console.log("LOGAR: " + this.nameFormControl.valid);
      console.log("LOGAR: " + this.termsFormControl.valid);
    }
  
    Logar() {
      if (this.nameFormControl.valid &amp;&amp; this.emailFormControl.valid &amp;&amp; this.termsFormControl.valid) {
        this.userName = this.name + ";" + this.email;
        this.uri = "#" + this.ssid + "&amp;sessionId=" + this.sessiondId + "&amp;ip=" + this.ip + "&amp;mac=" + this.mac + "&amp;ufi=" + this.ufi + "&amp;mgmtBaseUrl=" + this.mgmtBaseUrl + "&amp;clientRedirectUrl=" + this.clientRedirectUrl + "&amp;req=" + this.req + "&amp;username=" + this.userName + "&amp;hmac=" + this.hmac;
        // console.log("LOGAR: " + this.nameFormControl.valid);
        this.document.location.href = this.uri;
      }
      console.log("LOGAR: " + this.nameFormControl.valid);
      console.log("LOGAR: " + this.termsFormControl.valid);
    };
  
    emailFormControl = new FormControl('', [
      Validators.required,
      Validators.email,
    ]);
  
    nameFormControl = new FormControl('', [
      Validators.required,
    ]);
  
    termsFormControl = new FormControl('', [
      Validators.required,
    ]);
  
  }
  </code></pre>