简体   繁体   English

如何修复angular7中的“无法读取未定义的属性”错误”?

[英]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.

相关问题 如何修复无法读取 Angular 中未定义的属性 - How to fix Cannot read property of undefined in Angular Angular7 FullCalendar错误:无法读取未定义的属性“ length” - Angular7 FullCalendar error: Cannot read property 'length' of undefined 无法在ngOnInit()Angular7上读取未定义的属性“id” - Cannot read property 'id' of undefined on ngOnInit() Angular7 类型错误:无法读取未定义的 angular7 的属性“_id” - TypeError: Cannot read property '_id' of undefined angular7 如何修复Angular post请求中的“无法读取未定义的属性”错误 - How to fix 'Cannot read property of undefined' error in Angular post request 如何正式修复angular中的“无法读取未定义的属性'选项'”? - How to fix “Cannot read property 'options' of undefined” in angular formly? 如何修复无法读取Angular Material中未定义的属性&#39;time&#39;? - How to fix Cannot read property 'time' of undefined in Angular Material? 如何修复angular2-signaturePad中的“无法读取未定义的属性&#39;toDataURL&#39;” - How to fix "Cannot read property 'toDataURL' of undefined" in angular2-signaturePad 如何修复无法读取 angular 数据表上未定义的属性“长度” - how to fix Cannot read property 'length' of undefined on angular datatable 无法读取角度2中未定义的属性“错误” - Cannot read property 'errors' of undefined in angular 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM