微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angularjs – 有没有办法重置Angular中触及的$?

我正在尝试为我的表单实现“重置”按钮.我的一些文本字段使用$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().

原文地址:https://www.jb51.cc/angularjs/142462.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐