[英]How to fix 'Cannot read property 'errors' of undefined' in angular7?
Material Validation 材料验证
Quantity is required 数量为必填项
<div *ngIf="quantity.errors.minlength">should be greater than one</div>
I expect that the quantity field should validate only integers no decimal and it should be greater than one. 我希望数量字段只能验证整数,不能验证小数,并且应该大于1。
如果是被动式,可以尝试一下
*ngIf="form.get('quantity').hasError('minlength')"
You can use ?
可以用?
in property binding: 在属性绑定中:
<div *ngIf="quantity?.errors.minlength">should be greater than one</div>
This won't throw any errors for not having any errors
on quantity. 这不会引发任何错误,不具有任何errors
的数量。 and when any errors are bound to quantity the message will show up. 当任何错误必然要数量时,该消息就会出现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.