Angular Material MatChipList MatError 在没有焦点的情况下设置 errorstate 时不可见

Rob*_*hof 2 angular-material angular-material2 angular

我在芯片列表上显示 mat-error 时遇到了一些问题。根据这个 GitHub问题errorState明确设置以显示 mat-error。

此解决方案工作正常,但仅当芯片列表具有焦点时才有效。当芯片列表未聚焦时,它不起作用。看这个例子。就我而言,当芯片列表没有焦点时,由于某些 API 调用,有效水果列表稍后会发生变化。

当芯片列表没有焦点时,如何显示 mat-error?

Mar*_*hal 6

设置errorState似乎在没有焦点的情况下工作,由占位符和下划线转动指示red

我怀疑您mat-error也需要显示,但是,您缺少*ngIf.

<mat-error *ngIf="chipList.errorState">Too many chips</mat-error>

堆栈闪电战

https://stackblitz.com/edit/angular-matchiplist-with-error-message-tsdxfa?file=app/chips-input-example.html