角度2 - 验证

时间:2017-06-21 16:30:05

标签: angular

针对Reactive Forms的Ang2验证问题。

尝试过这些 - 但没有运气......

这里是代码....

需要帮助.... 反应表单验证 - 验证FormArray元素......



<input class="form-control g-remove-margin-bottom" value="" type="text" formControlName="myName"   required>
<div *ngIf="myForm.controls['myName'].hasError('required') && myForm.controls['myName'].touched" class="alert alert-danger">
Please enter  form name
</div>
            
			
SomeAcct is the formArray in the DOM	 like... <div class="row"  formArrayName="SomeAcct">......</div>	
<input class="form-control g-remove-margin-bottom" value="" type="text" formControlName="myAcct"   required>
<div *ngIf="myForm.controls.SomeAcct.controls.['myAcct'].hasError('required') && myForm.controls.SomeAcct.controls.['myAcct'].touched" class="alert alert-danger">
Please enter Acct Num
</div>

Used this one too in the markup 
<input class="form-control g-remove-margin-bottom" value="" type="text" formControlName="myAcct"   required>
<div *ngIf="myForm.get('SomeAcct').get('myAcct').touched " class="alert alert-danger">Please enter Acct Number</div>
            
&#13;
&#13;
&#13;

SomeAcct是DOM中的formArray,如...... ......

请输入Acct Num

在标记中也使用了这个

请输入帐号

0 个答案:

没有答案