Answers for "angular material mat-error on http request"


angular material mat-error on http request

// first define our formcontrol object
control = new FormControl('', [Validators.required])

//http method:
submit() {
  //call api
  // assume you got an error (Unauthorized, BadRequest, ...)
  //this set control to errored status and thus,
  //mark formcontrol/formgroup as invalid
  this.control.setErrors({error_key: true})

// in your html code :
  <input type="text" formControlName="control" matInput />
  <mat-error *ngIf="control.hasError('required')">
  	Control cannot be empty
  <mat-error *ngIf="control.hasError('error_key')">
  	My custom error message
Posted by: Guest on April-17-2020

Code answers related to "angular material mat-error on http request"

Code answers related to "Javascript"

Browse Popular Code Answers by Language