gpt4 book ai didi

javascript - 无法使用 '$setPristine' 重置表单

转载 作者:行者123 更新时间:2023-12-02 16:02:28 26 4
gpt4 key购买 nike

当我运行以下代码来重置表单时出现错误:

 $scope.saveFormData = function () {
$scope.testForm.$setPristine();
}

和 HTML:

<form name="testForm" >

<label class="item item-input item-stacked-label">
<span class="input-label">Title</span>
<input type="text" ng-model="formData.shortDesc" required="">
</label>
<button class="button button-block button-positive" type="submit" ng-click="saveFormData()" >Opslaan </button>

</form>

最佳答案

它工作正常,这是 JSFiddle ,尝试在表单存在的情况下添加条件,但我不知道你得到什么错误:

function MyCtrl($scope) {
$scope.saveFormData = function() {
if ($scope.testForm) {
$scope.testForm.$setPristine();
$scope.formData = {};
}
};
}

关于javascript - 无法使用 '$setPristine' 重置表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31068320/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com