如何在不知道輸入名稱的情況下觸發錯誤消息?請參見下面的代碼:如何通過ng-messages指令獲取元素inputName?
<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
。但輸入將自動生成並附加,因此我不能寫入名稱,因爲生成器會設置名稱。我必須獲得輸入名稱。我該怎麼做?
有你嗎嘗試:'myForm [field.field_id]。$ error'? –