when reseting the data in a form, wish to set form.setPristine(), but the formController is not yet registered in $scope.
this may seem like a dumb question, but how can I find the formController?
in the code below, get "TypeError: Cannot call method 'setPristine' of undefined"
index.html
<ng-form name='wordForm' ng-controller='wordCntl' > ... </ng-form>
word.js
var langMod = angular.module('langMod', []);
langMod.controller( 'wordCntl', function($scope,$http,$location) {
// data
$scope.dflt = { wrd_id: '', usr_id: '', ln: '', word: '' };
$scope.orig = {};
$scope.data = {};
// pull record default
$scope.reset = function() {
$scope.orig = angular.copy($scope.dflt);
$scope.data = angular.copy($scope.orig);
$scope.wordForm.setPristine();
}
$scope.reset();
};
the only way I know to get to the formController is when it's been set in the $scope. but it's not there yet, and I do not know how to find it.
$scope.wordFormfor undefined\null before calling this method. If the form is not there once its loaded it would be in pristine state already.$setPristine()notsetPristine().