在angular2中设置无效的无效表单控件
set invalid invalid form control in angular2
是否可以在angular2中设置为无效表单控件? (使用表单生成器)
eg. i have form-> exampleFrom & field-> exampleControl
我试过了,没成功:
this.exampleFrom.controls['exampleControl'].invalid
尝试
let control = this.exampleFrom.controls['exampleControl'];
control.setErrors({backend: {someProp: "Backend message"}});
let message = control.errors['backend'].someProp;
尝试使用此代码打印消息
<div style='color:red' *ngIf="!exampleFrom.exampleControl.valid">
//set here your custom message
</div>
是否可以在angular2中设置为无效表单控件? (使用表单生成器)
eg. i have form-> exampleFrom & field-> exampleControl
我试过了,没成功:
this.exampleFrom.controls['exampleControl'].invalid
尝试
let control = this.exampleFrom.controls['exampleControl'];
control.setErrors({backend: {someProp: "Backend message"}});
let message = control.errors['backend'].someProp;
尝试使用此代码打印消息
<div style='color:red' *ngIf="!exampleFrom.exampleControl.valid">
//set here your custom message
</div>