I have the following field in an NgForm:
<input type="text" name="depVarName" [(ngModel)]="variable.depVarName"
#depVarName="ngModel" id="depVarName"
[required]="'depSelected>0'" />
<div *ngIf="submitted" class="errorMsg">
<label *ngIf="depVarName.control.hasError('required')">Dependency is required</label>
</div>
The problem is that this field is always required, regardless of the [required] related condition depSelected>0. depSelected is not a DOM element, could that be the problem?
Currently 'depSelected>0'(non-empty string) is considered as truthy and that's why field marked as required. The expression inside require attribute should be without '(single qoute).
[required]="depSelected>0"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With