我正在通过 json 中的 ng-repeat 创建动态。
我的 form.html
<form name="userForm" >
<div ng-repeat="(key,box) in form.form_fields" >
<accordion >
<accordion-group heading="{{key}}" is-open="true">
<div ng-repeat="field in box">
<field-directive field="field">
</field-directive>
</div>
</accordion-group>
</accordion>
</div>
</form>
所以基本上我正在通过指令加载每种类型的字段(文本框/收音机/下拉/电子邮件等)html槽循环。我正在使用 $compile 和链接器加载这些小 HTML。一切都很好,甚至验证也是如此。我能够根据表单验证启用/禁用提交按钮,除了ng-message。如果我不使用这样的指令
<form name="userForm" >
<div ng-repeat="(key,box) in form.form_fields" >
<accordion >
<accordion-group heading="{{key}}" is-open="true">
<div ng-repeat="field in box">
<div class="col-md-3 col-sm-6 col-xs-12" ng-if="field.field_type ==='textfield' ">
<md-input-container >
<label>{{field.field_title}}</label>
<input ng-model="field.field_value" name="{{field.field_id}}" type="text"
ng-required="true" md-maxlength="9" >
<div ng-messages="userForm.{{field.field_id}}.$error">
<p ng-message="maxlength">Your name is too long.</p>
<p ng-message="required">Your name is required.</p>
</div>
</md-input-container>
</div>
<div class="col-md-3 col-sm-6 col-xs-12" ng-if="field.field_type ==='number' ">
<md-input-container >
<label>{{field.field_title}}</label>
<input ng-model="field.field_value" name="{{field.field_id}}" type="text"
ng-required="true" md-maxlength="9" >
<div ng-messages="userForm.{{field.field_id}}.$error">
<p ng-message="maxlength">Your name is too long.</p>
<p ng-message="required">Your name is required.</p>
</div>
</md-input-container>
</div>
</div>
</accordion-group>
</accordion>
</div>
</form>
一切正常,包括 ng-message。我也可以看到错误消息。如果我使用指令,ng-message 有什么问题。请帮忙。