误差与角度2形式所需的区别

时间:2019-03-27 11:27:05

标签: validation angular6 angular5 angular2-forms angular7

我正在使用角度2模板驱动形式工作。我有一个问题。value.errors.required和value.errors有什么区别。任何人都可以清楚地解释吗?如果我使用必填项,则会收到类似“ ERROR 错误:无法读取null属性“ required”。正确的是“ zipcode.errors.required”(或zipcode.errors)

演示:https://stackblitz.com/edit/angular-6-template-driven-form-validation-kdkans?file=app/app.component.html

<div *ngIf="zipcode1.invalid || zipcode2.invalid)&&forms.submitted&& 
(zipcode1.errors.required || zipcode2.errors.required")>

<div *ngIf="zipcode1.errors.required || zipcode2.errors.required">Please 
type</div>

</div>

 <div *ngIf="zipcode1.invalid || zipcode2.invalid)&&forms.submitted&& 
(zipcode1.errors.required || zipcode2.errors.required ")>

<div *ngIf="zipcode1.errors.required || zipcode2.errors.required">Please 
type</div>

</div>

<div *ngIf="zipcode1.errors|| zipcode2.errors">Please type</div>

</div>

<div *ngIf="zipcode1.invalid || zipcode2.invalid)&&forms.submitted&& 
(zipcode1.errors|| zipcode2.errors")>

<div *ngIf="zipcode1.errors|| zipcode2.errors">Please type</div>

 </div>

0 个答案:

没有答案