Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t使用'重置表单$原始的';_Javascript_Angularjs_Ionic - Fatal编程技术网

Javascript Can';t使用'重置表单$原始的';

Javascript Can';t使用'重置表单$原始的';,javascript,angularjs,ionic,Javascript,Angularjs,Ionic,运行以下代码重置表单时出错: $scope.saveFormData = function () { $scope.testForm.$setPristine(); } 和HTML: <form name="testForm" > <label class="item item-input item-stacked-label"> <span class="inpu

运行以下代码重置表单时出错:

 $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>

标题
奥普斯兰

它工作正常,下面是一个示例,如果表单存在,请尝试添加条件,但我不知道会出现什么错误:

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

也许你应该添加你得到的错误消息。这里是:无法读取未定义的属性“$setPristine”。错误是说它找不到应该在属性名下的作用域中的Angular
FormController
。实现这一点的一种方法是使用创建另一个作用域的指令,如(ng if、ng include等)。如果您仍然需要解决错误,您可以向我们展示更多的HTML(从指定控制器的位置开始,一直到表单)。非常感谢。我的目标是清除文本字段。还是我使用了错误的函数?@EdzoBlaauw您使用了错误的函数:)
$setPristine()
重置表单验证错误以及表单是否“脏”。要清除文本字段,应将模型设置为空字符串或null。此外,还可以将saveFormData()函数调用放在表单上。它将同时执行表单提交和单击操作。谢谢大家@Sunil和@Riyaj!!今天学到了一些东西:))刚刚更新了帖子,并用小提琴重置了表单数据