I have forked your jsfiddle for showing you how to do it: https://jsfiddle.net/fpt5kcba/2/
As you assigned a name to the form, name="mv.form"
you can access it by the same way in your controller.
angular.module('myApp', []).controller('myCtrl', function () {
var mv = this;
mv.reset = function () {
mv.text='';
mv.form.$setPristine();
}
});
EDIT:
If what you want is to make it dynamically, take a look at this jsfiddle: https://jsfiddle.net/fpt5kcba/5/
This is the way:
<div ng-app="myApp" ng-controller="myCtrl as mv">
<div ng-repeat="form in mv.forms">
{{form.id}}
<form name="mv.{{form.id}}">
<input ng-model="form.text"><br>
<a href="#" ng-show="mv[form.id].$dirty" ng-click="mv.reset(form.id, $index)">reset</a>
</form>
</div>
</div>
Controller:
angular.module('myApp', []).controller('myCtrl', function ($scope) {
var mv = this;
mv.forms = [
{
id: "form1",
text: ""
},
{
id: "form2",
text: ""
}];
mv.values = {
form1: "",
form2: ""
};
mv.reset = function (formId, index) {
mv.text='';
mv.forms[index].text = "";
mv[formId].$setPristine();
}
});
Take always in count that $setPristine is not used for clearing fields.
Sets the form to its pristine state.
This method can be called to remove the 'ng-dirty' class and set the
form to its pristine state (ng-pristine class). This method will also
propagate to all the controls contained in this form.
Setting a form back to a pristine state is often useful when we want
to 'reuse' a form after saving or resetting it.