0

我会得到错误,比如字段变红,显示字符数变红。但是没有显示错误信息。在控制台中没有发现错误。我还添加了 angular-1.3.4 ngMessages 依赖项。请帮忙。

<div class="col-md-3 col-sm-6 col-xs-12">
<md-input-container flex>
          <label>{{field.field_title}}</label>
          <input ng-model="field.field_value" name="username" type="text" placeholder="Placeholder text"  
            ng-required="field.field_required" md-maxlength="field.max" >

     <div ng-messages="userForm.username.$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>
4

1 回答 1

0

保持输入字段的这些属性简单:

ng-minlength=3 ng-maxlength=20 需要

这是我的验证工作代码:

<form name="signup_form" novalidate ng-submit="signupForm()">
  <fieldset>
    <legend>Signup</legend>
    <div class="row">
      <div class="large-12 columns">
        <label>Your name</label>
        <input type="text" 
            placeholder="Name" 
            name="name" 
            ng-model="signup.name" 
            ng-minlength=3 
            ng-maxlength=20 required />
       <div class="error-container" 
            ng-show="signup_form.name.$dirty && signup_form.name.$invalid && signup_form.submitted">
        <small class="error" 
            ng-show="signup_form.name.$error.required">
            Your name is required.
        </small>
        <small class="error" 
                ng-show="signup_form.name.$error.minlength">
                Your name is required to be at least 3 characters
        </small>
        <small class="error" 
                ng-show="signup_form.name.$error.maxlength">
                Your name cannot be longer than 20 characters
        </small>
      </div>
      </div>
    </div>
    <button type="submit" class="button radius">Submit</button>
  </fieldset>
</form>
于 2015-10-03T08:50:49.207 回答