Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 我无法在mat芯片中显示mat错误_Angular_Validation - Fatal编程技术网

Angular 我无法在mat芯片中显示mat错误

Angular 我无法在mat芯片中显示mat错误,angular,validation,Angular,Validation,我有这个简单的角度形式 ngOnInit(): void { this.tagInput.errorState = true; this.questionForm = this.fb.group({ tagsControl:['',[ Validator.required ]] },{updateOn:'submit'}) } 这是我的html <form> <mat-form-field class=&q

我有这个简单的角度形式

ngOnInit(): void {
    this.tagInput.errorState = true;
    this.questionForm = this.fb.group({
      tagsControl:['',[
        Validator.required
      ]]
    },{updateOn:'submit'})
}

这是我的html

<form>
  <mat-form-field class="example-chip-list" appearance="outline">
    <mat-label>Tags</mat-label>
      <mat-chip-list #tagInput>
          <mat-chip
           *ngFor="let tag of tags"
           [selectable]="selectable"
           [removable]="removable"
           (removed)="remove(tag)">
           {{tag}}
           <mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
          </mat-chip>
          <input
           placeholder="Add upto 3 tags to describe what your question is about"
           formControlName="tagsControl"
           [matAutocomplete]="auto"
           [matChipInputFor]="tagInput"
           [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
           (matChipInputTokenEnd)="add($event)">
                      
          </mat-chip-list>
          <mat-error>You should add atleast 3 tags.</mat-error>
          <mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
          <mat-option *ngFor="let tag of filteredTags | async" [value]="tag">
             {{tag}}
          </mat-option>
         </mat-autocomplete>
       </mat-form-field>
      <button  mat-button type="submit">Post Question</button>
    </form>


标签
{{tag}}
取消
您应该添加至少3个标记。
{{tag}}
张贴问题

我从angular material chip文档中复制了标记系统。现在我想在提交表单时显示错误。当标记数不在3到5之间时,应该显示错误。但我不知道如何显示错误。

您必须使用自定义验证。您可以继续学习本教程,它与您的教程非常相似。