以此形式为例http://plnkr.co/edit/fHEBw6dDdG3IVgnmCLb7?p=preview
如何$pristine在SAVE DRAFT按下按钮后将表单状态设置为true ?
mus*_*_ut 23
你可以叫$setPristine上form:http://plnkr.co/edit/wXaFXtuhNH6d4SP2uArm?p=preview
<button ng-click="reset(); form.$setPristine()">RESET</button>
<button ng-click="update(user); form.$setPristine()">SAVE</button>
Run Code Online (Sandbox Code Playgroud)
或者您可以在控制器中调用该方法(在确保表单存在之后):
$scope.update = function(user) {
$scope.master= angular.copy(user);
if ($scope.form) $scope.form.$setPristine();
};
$scope.reset = function() {
$scope.user = angular.copy($scope.master);
if ($scope.form) $scope.form.$setPristine();
};
Run Code Online (Sandbox Code Playgroud)
演示:http://plnkr.co/edit/Mau7uuDfPlzcn418OdWh?p=preview