我不知道在角稳定版1.0.8中我该怎么做。问题是在验证的形式,我把一个值,然后按重置按钮我有不必要的消息“无效的价格”(我知道该形式是$ dirty所以我应该设置$ pristne)。 在棱角1.1.1我可以打电话:
$scope.advertForm.$setPristne();
但是如何在角度1.0.8中替换它。
我的表格:
<form ng-controller="AddAdvertController" name="advertForm" novalidate>
<label>Price ($)</label>
<input ng-model="newAdvert.price" type="number" name="price" min="100" required>
<span ng-show="advertForm.price.$dirty && advertForm.price.$invalid">Invalid price</span>
<br/>
<button ng-click="reset()" ng-disabled="isUnchanged()">Reset</button>
<button ng-click="add()" ng-disabled="advertForm.$invalid || isUnchanged()">Save</button>
</form>
我的控制器:
motoAdsApp.controller('AddAdvertController', ['$scope',
function($scope) {
$scope.emptyAdvert = {
price: null
};
$scope.add = function() {
alert('User added!');
$scope.reset();
};
$scope.reset = function() {
$scope.newAdvert = angular.copy($scope.emptyAdvert);
if ($scope.advertForm) {
// In angular 1.1.1 or higher
//$scope.advertForm.$setPristne();
// How to do in angular 1.0.8?
}
};
$scope.isUnchanged = function() {
return angular.equals($scope.newAdvert, $scope.emptyAdvert);
};
$scope.reset();
}
]);