简体   繁体   中英

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.

如果是被动式,可以尝试一下

*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. and when any errors are bound to quantity the message will show up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM