angularjs – 有没有办法重置Angular中触及的$?
发布时间:2020-12-17 07:35:09 所属栏目:安全 来源:网络整理
导读:我正在尝试为我的表单实现“重置”按钮.我的一些文本字段使用$touch来确定是否显示错误.但是一旦设置了$touch标志,当我重置模型时,$touch不会被重置,因此我的错误消息仍然可见. div class="col-sm-4" ng-class="{'has-error' : donationForm.firstName.$inva
我正在尝试为我的表单实现“重置”按钮.我的一些文本字段使用$touch来确定是否显示错误.但是一旦设置了$touch标志,当我重置模型时,$touch不会被重置,因此我的错误消息仍然可见.
<div class="col-sm-4" ng-class="{'has-error' : donationForm.firstName.$invalid && donationForm.firstName.$touched}"> <label for="firstName" class="control-label">First Name</label> <input type="text" id="firstName" name="firstName" class="form-control" ng-model="editableDonation.person.firstName" ng-required="true" ng-maxlength="20" /> <span class="help-block" ng-show="donationForm.firstName.$error.required && donationForm.firstName.$touched"> First Name is required. </span> <span class="help-block" ng-show="donationForm.firstName.$error.maxlength"> First Name is too long (20 max). </span> </div> 有没有办法做到这一点? 我的resetForm: $scope.resetForm = function () { $scope.donationForm.$setPristine(); $scope.model = ''; $scope.donation = donationService.defaultDonation; $scope.editableDonation = angular.copy($scope.donation); }; http://plnkr.co/edit/Oa91ZkTatsddSA4oujQK
DeborahK89指出我可以使用:
$scope.donationForm $setUntouched(). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |