2
我使用角JS 1.6setPristine和setUntouched沒有工作
<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();
}
});
任何更新!
是ConductCode形式的名字嗎?它看起來不是。另外,$ setPristine()在表單上不是用於輸入。 – rrd
'CentreFromOtherConductForm'表單名稱和'ConductCode'是元素名稱'md-select name =「ConductCode」'@rrd –