<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
中