Angular js:在页面加载完成后显示错误消息?

时间:2016-09-21 11:52:42

标签: angularjs

我创建了简单的登录表单并对其进行了验证,但问题是在页面加载期间进行了验证。我在这里oode。



<body ng-controller="myCont">
 <form name="myForm" novalidate>
  <h2 align="center">Add The Item Here</h2>	
    <table align="center" border="2">
     <div class="control-group">
        <div class="controls">      		    
			    <tr>
				   <td>pid</td>
					 <td><input type="number" name="pid" ng-model="user.pid" ng-maxlength="3" required="pid" ></td>
                      <td ng-show="myForm.pid.$touched  && myForm.pid.$invalid"></td>
                    <td ng-show="myForm.pid.$error.required"  style="color:red">Enter Pid</td>
                    <td ng-show="myForm.pid.$error.maxlength" style="color:red">Only 3 digits for pid</td>
                   
 				</tr>
                <tr>
				    <td>pname</td>
					  <td><input type="text" name="pname" ng-model="user.pname" required="pname"></td>
					  <td style="color:red" ng-show="myForm.pname.$touched && myForm.pname.$invalid"></td>
                    <td ng-show="myForm.pname.$error.required" style="color:red">Pname is required.</td>
                </tr>
    	        <tr>
					<td>pcost</td>
					  <td><input type="number" name="pcost" ng-model="user.pcost" required="pcost"></td>
					  <td style="color:red" ng-show="myForm.pcost.$touched && myForm.pcost.$invalid">
                    <td ng-show="myForm.pcost.$error.required" style="color:red">Pcost is required.</td>

                </tr>
                   <div ng-repeat="x in result track by $index"></div>
				<tr>
			      <td>AddData<input type="submit" ng-disabled="myForm.$invalid" ng-click="addAll()">
                  </td> 
			       <td><input type="reset" name="reset" value="reset"></td>
			    </tr>  
			
</div>
</div>
      </table>
    </form>
  </body>
&#13;
&#13;
&#13;

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试angular-toastr通知错误的凭据或错误消息... 希望它会有所帮助