【问题标题】:TypeError: Cannot set property '$pristine' of undefinedTypeError:无法设置未定义的属性'$pristine'
【发布时间】:2015-09-09 07:17:54
【问题描述】:

我正在使用 AngularJS v1.3.16。我想重置表单。

我尝试了$pristine$dirty$setPristine(),但收到了错误消息:

HTML:

<form id="userForm" class="form-horizontal ut-form form-validation" role="form" name="userForm" novalidate>
.........
</form>

代码:

    $scope.createUser = function () {
        $scope.page.view = 'create';
        $scope.account = "";
        $scope.userForm.$pristine = true;
    }

错误信息:

  1. $setPristine() - 类型错误:无法读取属性 '$setPristine' of undefined

  2. $pristine - 类型错误:无法设置属性 '$pristine' of undefined

请任何人建议我如何解决这个问题。

【问题讨论】:

标签: html angularjs form-control


【解决方案1】:

您可以为此使用表单名称。

在你的情况下:

$scope.userForm.$setPristine()

或者直接在 HTML 中:

userForm.$setPristine()

【讨论】:

  • 正在在他的代码中使用表单名称,他说他已经尝试过$setPristine()
  • 我已经尝试过 $setPristine() 然后我得到 TypeError: Cannot read property '$setPristine' of undefined
猜你喜欢
  • 2021-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-20
  • 2022-08-16
  • 2018-08-13
相关资源
最近更新 更多