Currently, I am attempting to implement a form within an Angular 1.5 component.
The form is functional as I have successfully achieved model binding and can access the data upon submission. However, the final piece of the puzzle that is missing is the ability to reset the form properly using $setPristine.
I have tried a few different methods, with my initial approach involving passing the form as an argument to the reset function.
In my form.html file:
<form name="$ctrl.userForm">
...
<input class="btn btn-default" type="button" ng-click="$ctrl.reset($ctrl.userForm)" value="Reset" />
</form>
And in my form.component.js file:
ctrl.reset = function(userForm) {
ctrl.user = {};
userForm.$setPristine // This returns: Cannot read property '$setPristine' of undefined
};
You can view the full code on Plnkr here.
I also attempted initializing $ctrl.userForm as an empty object during $onInit, but this did not yield the desired result either. Removing the $setPristine line allows the reset function to clear the form's data, however, it does not reset its state from an Angular perspective.
If anyone has any insights or ideas on what might be missing, I would greatly appreciate the help.