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
Angularjs 如何修复Angular JS中的$setPristine错误?_Angularjs - Fatal编程技术网

Angularjs 如何修复Angular JS中的$setPristine错误?

Angularjs 如何修复Angular JS中的$setPristine错误?,angularjs,Angularjs,我有Angular JS中的函数,它重置HTML表单: $scope.resetForm = function (formName) { $scope.formData = angular.copy(formEdit); $scope.formName.$setPristine(); } HTML如下所示: <form name="educAddForm" novalidate> <div ng-click="resetForm(educAddForm)">

我有Angular JS中的函数,它重置HTML表单:

$scope.resetForm = function (formName)
{
   $scope.formData = angular.copy(formEdit);
   $scope.formName.$setPristine();
}
HTML如下所示:

<form name="educAddForm" novalidate>
<div ng-click="resetForm(educAddForm)">Click</div>

+1对PSL的评论。改变

$scope.formName.$setPristine()

formName.$setPristine()


请记住,因为formName正在传入函数,所以即使传入了作用域变量,也应该在函数的作用域中将其作为参数名引用。

$scope.formName.$setPristine()
更改为
formName.$setPristine()
$scope.resetForm = function (formName)
{
   $scope.formData = angular.copy(formEdit);
   formName.$setPristine();
}
$scope.resetForm = function (formName)
{
   $scope.formData = angular.copy(formEdit);
   formName.$setPristine();
}