ng-messages中使用的属性值不起作用

时间:2016-07-26 10:04:43

标签: javascript angularjs

我是angular js的新手,我开发了一个Employee网页,我必须提供参考列表。以下代码无效



<form name="referForm" data-ng-submit="upsertReferences(this)" method="post">
            <div class="text-label" >
                <input type="text" id="r_fullname_{{index}}" ng-minlength="4"
                       data-ng-attr-class="{ 'error': (referForm.r_fullname_{{index}}.$dirty) && (referForm.r_fullname_{{index}}.$invalid) }"
                       name="r_fullname_{{index}}" data-ng-attr-model="reference.fullname" data-ng-pattern="/^[a-zA-Z]+$/"  required="required"
                       data-ng-model-options="{ updateOn: 'submit' }"/>
                <label for="r_fullname_{{index}}">Full Name</label>
            </div>
            <div data-ng-message-exp="referForm.r_fullname_{{index}}.$error" data-ng-show="referForm.r_fullname_{{index}}.$touched">
                <div class="error-message" data-ng-messages="required">Please enter your name.</div>
                <div class="error-message" data-ng-show="(referForm.r_fullname_{{index}}.$error.minlength )&&!(referForm.r_fullname_{{index}}.$error.pattern)">Your field is too short</div>
                <div class="error-message" data-ng-show="referForm.r_fullname_{{index}}.$error.pattern" >Enter Aplhabets Only</div>--!>

            </div>
</form>
&#13;
&#13;
&#13;

因为在ng-messages,ng-show,ng-hide中使用{{index}}时出错,我用这个替换了它们。$ eval(index)[&#39; $ error&#39;]但是仍然验证不起作用。所以我已经移出ng-messages并开始使用ng-if

&#13;
&#13;
<div data-ng-if="error_one" data-ng-attr-value="referForm.r_fullname_{{index}}.$error">
                <div class="error-message" data-ng-messages="required">Please enter your name.</div>
                <div class="error-message" data-ng-if="length_error" data-ng-attr-value="(referForm.r_fullname_{{index}}.$error.minlength )&&!(referForm.r_fullname_{{index}}.$error.pattern)">Your field is too short</div>
                <div class="error-message" data-ng-if="number_error" data-ng-attr-value="referForm.r_fullname_{{index}}.$error.pattern" >Enter Aplhabets Only</div>
            </div>
&#13;
&#13;
&#13;

这也不起作用。非常感谢任何帮助。我正在努力完成任务,提前付款

0 个答案:

没有答案