如何在不知道输入名称的情况下触发错误消息?请参阅以下代码:
<input class="form-control"
id="{{field.field_id}}"
set-name="{{field.field_id}}"
type="text"
ng-model="field.field_value"
ng-minlength="field.field_char_num_min"
ng-maxlength="field.field_char_num_max"/>
<div ng-messages="don't know the input name yet" class="my-messages">
<div ng-message="minlength">Your field is too short</div>
<div ng-message="maxlength">Your field is too long</div>
</div>
在ng-messages
中应该写出输入错误的路径,例如myForm.inputName.$error
。但输入将自动生成并附加,因此我无法写入名称,因为生成器设置了名称。我必须得到一个输入名称。我该怎么办?
答案 0 :(得分:0)
在ng-message
中尝试这样的事情<form name="formName">
<input type="text" id="anyName" name="anyName" required/>
<span ng-show="formName.anyName.$error.required"> Please enter a value.</span>
</form>
答案 1 :(得分:0)
您可以使用field[field.field_id]['$invalid']
来确定字段是否有效,然后使用field[field.field_id]['$error']
show minlength
&amp; maxlength
错误
<强>标记强>
<div ng-show="field[field.field_id]['$invalid']" class="my-messages">
<div ng-message="field[field.field_id]['$error'].minlength">Your field is too short</div>
<div ng-message="field[field.field_id]['$error'].maxlength">Your field is too long</div>
</div>