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之间时,应该显示错误。但我不知道如何显示错误。您必须使用自定义验证。您可以继续学习本教程,它与您的教程非常相似。