【问题标题】:angularjs : clearing form after submit shows error message?angularjs:提交后清除表单显示错误消息?
【发布时间】:2015-05-25 04:07:53
【问题描述】:

您好,我有表格,我使用了许多字段。提交后,如果一切正常,我正在清除或将表单设置为默认状态,但我仍然收到错误消息。

<div>
        <span>Type:</span>
        <select class="chosen" name="type" required="" chosen="exp.transactionType" ng-model="exp.selectedTransactionType"
            ng-options="tt.value for tt in exp.transactionType">
        </select>
        <div class="error-msg" ng-show="form.$submitted || form.type.$touched">
            <span class="error-msg" ng-show="form.type.$error.required">Select transaction type.</span>
        </div>
    </div>

我在这里做错了吗?

【问题讨论】:

    标签: angularjs angular-ngmodel angularjs-validation


    【解决方案1】:

    您需要设置原始表单。 假设您的表单名称是“myForm”,那么在清除表单后,您可以执行以下操作

    $scope.myForm.$setPristine();
    

    【讨论】: