我使用的是 Angular js 1.6
<div flex="100" flex-gt-sm="50">
<md-input-container class="md-block"> <label>Conduct
Code</label> <md-select name="ConductCode" ng-model="conductcode"
style="min-width: 200px;" required> <md-option
ng-repeat="val in olCentreFromOtherConduct.conduct" ng-value="val.acadamiccalanderid" ng-bind="val.condcutcode"></md-option>
</md-select>
<div ng-messages="CentreFromOtherConductForm.ConductCode.$error">
<div ng-message="required">Please Select Conduct Code</div>
</div>
</md-input-container>
</div>
当我重置值时
$scope.Reset = function () {
$scope.conductcode = 0;
}
那么它的状态应该是untouch!!我尝试了以下不同的方法,但没有任何效果
// $scope.CentreFromOtherConductForm.ConductCode.$touched = true;
// $scope.CentreFromOtherConductForm.ConductCode.$valid = true;
// $scope.CentreFromOtherConductForm.ConductCode.$invalid = false;
// $scope.CentreFromOtherConductForm.ConductCode.$setUntouched();
或者
angular.forEach($scope.CentreFromOtherConductForm, function (input) {
if (input && input.hasOwnProperty('$viewValue')) {
input.$setPristine();
input.$setUntouched();
}
});
任何更新!!!
最佳答案
答案是调用表单上的方法,而不是输入上的方法:
$scope.CentreFromOtherConductForm.$setPristine();
$scope.CentreFromOtherConductForm.$setUntouched();
关于angularjs - setPristine 和 setUntouched 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45979484/