我正在使用角度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;
}
然后它的状态应该是无法触摸!!我尝试过不同的事情,但没有任何工作
// $scope.CentreFromOtherConductForm.ConductCode.$touched = true;
// $scope.CentreFromOtherConductForm.ConductCode.$valid = true;
// $scope.CentreFromOtherConductForm.ConductCode.$invalid = false;
// $scope.CentreFromOtherConductForm.ConductCode.$setUntouched();
OR
angular.forEach($scope.CentreFromOtherConductForm, function (input) {
if (input && input.hasOwnProperty('$viewValue')) {
input.$setPristine();
input.$setUntouched();
}
});
任何更新!!!
答案 0 :(得分:1)
答案是调用表单上的方法,而不是输入:
$scope.CentreFromOtherConductForm.$setPristine();
$scope.CentreFromOtherConductForm.$setUntouched();