AngularJS重置表单 ng-dirty

前端之家收集整理的这篇文章主要介绍了AngularJS重置表单 ng-dirty前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<divng-app="myApp"ng-controller="myCtrlasctrl">
<formname="ctrl.myForm">
<div><labelfor="email">Email</label>
<inputname="myInput"type="email"ng-model="ctrl.email"id="email"required></div>
<div><labelfor="password">Password</label>
<inputname="myPassword"type="password"minlength="8"ng-model="ctrl.password"id="password"required></div>
<div>
<buttonng-click="ctrl.reset()"type="button">Reset</button>
</div>
</form>
angular.module('myApp',[])
.controller('myCtrl',myCtrl);
functionmyCtrl(){varvm=this;
vm.reset=function(){
vm.myForm.$setPristine();
vm.myForm.$setUntouched();
vm.email=vm.password='';
}
}

表单input区域必须放在 form

参考连接:Angular clear subform data and reset validation

原文链接:https://www.f2er.com/angularjs/146780.html

猜你在找的Angularjs相关文章