重置表单中的数据时,希望设置form.setPristine(),但formController尚未在 $scope 中注册。
这似乎是一个愚蠢的问题,但我怎样才能找到formController?
在下面的代码中,得到“TypeError:无法调用未定义的方法'setPristine'”
索引.html
<ng-form name='wordForm' ng-controller='wordCntl' > ... </ng-form>
word.js
var langMod = angular.module('langMod', []);
langMod.controller('wordCntl', function($scope,$http,$location) {
// 数据
$scope.dflt = { wrd_id: '', usr_id: '', ln: '', word: '' };
$scope.orig = {};
$scope.data = {};
// 拉取记录默认
$scope.reset = 函数() {
$scope.orig = angular.copy($scope.dflt);
$scope.data = angular.copy($scope.orig);
$scope.wordForm.setPristine();
}
$scope.reset();
};
我知道到达的唯一方法formController是当它被设置在$scope. 但它还没有,我不知道如何找到它。