0
我在電子郵件的表單中進行了驗證。如果用戶已經註冊,它將顯示警報,並用空值重置表單。我需要警報消息以及數據應保留在表單中。 在此先感謝。 https://plnkr.co/edit/WhdRmJmLs69yaf6Q2uYI?p=preview如何在angularjs中驗證錯誤後保留表單中的值
<div class="form-group">
<label class="control-label col-sm-2" for="firstName">First Name:</label>
<div class="col-xs-4">
<input type="text" class="form-control" id="firstName" ng-disabled="!edit" name="firstName" ng-model="user.firstName" ng-required="true">
<span style="color:red" ng-show="userForm.myName.$touched && userForm.myName.$invalid">Please enter a First Name</span>
</div>
<label class="control-label col-sm-2">Email:</label>
<div class="col-xs-4"><input type="email" id="email" class="form-control" ng-disabled="!edit" name="email" ng-model="user.email" ng-required="true">
<span style="color:red" ng-show="userForm.email.$touched && userForm.email.$invalid">Please enter valid email ID</span>
</div>
</div>
<div class="panel-footer">
<button type="button" ng-click='edit=!edit'id="Edit" ng-show="!edit" class="btn btn-default" >Edit</button>
<button ng-show="edit" id="save" type="submit" ng-click='addOrModifyUser(user)' class="btn btn-default"
ng-disabled="userForm.$invalid">Save
</button>
<a ng-if="user.accountId" ui-sref="account.locations.contacts({accountId: user.accountId})">
<button type="type" class="btn btn-default">Cancel</button>
</a>
</div>
我?P =預覽
將其保存在$ http調用之前的另一個變量中以驗證唯一性。 –
你的plunk不是演示你有問題的工作演示。該HTML頁面甚至不包含Angular JS文件。 – Hoa
您是否正在檢查電子郵件的唯一性?然後以指導方式行事。現在你正在使用'$ state.reload()'和'$ location.path()'來重新加載整個頁面,所以顯然你會丟失所有的數據。 –