更新时间:2023-11-25 16:24:58
是的,您可以访问长度的数字,包括maxlength和minlength.您可以在error
对象中的.maxlength.requiredLength
&&下找到它. minlength.requiredLength
.还有一个带有actualLength
的字段,但是您似乎不需要它,但是有时您会需要它! :)
Yes, you can access the number of the length, both in maxlength and minlength. You can find it inside the error
object, where it lies under .maxlength.requiredLength
&& minlength.requiredLength
. There is also a field with actualLength
, but you don't seem to need it, but if you sometimes do! :)
<p *ngIf="formControl.hasError('maxlength')">
{{field}} at max {{formControl.errors.maxlength.requiredLength}} characters
</p>
<p *ngIf="formControl.hasError('minlength')">
{{field}} at least {{formControl.errors.minlength.requiredLength}} characters
</p>
DEMO