@@ -1054,8 +1054,8 @@ var inputType = {
1054
1054
* Since the element value should always reflect the current model value, a range input
1055
1055
* will set the bound ngModel expression to the value that the browser has set for the
1056
1056
* input element. For example, in the following input `<input type="range" ng-model="model.value">`,
1057
- * if I set `model.value = null`, the browser will set the input to `'50'`. Angular will then set
1058
- * the model to `50`, to prevent input and model value being out of sync.
1057
+ * if the application sets `model.value = null`, the browser will set the input to `'50'`.
1058
+ * Angular will then set the model to `50`, to prevent input and model value being out of sync.
1059
1059
*
1060
1060
* This does not only affect changes to the model value, but also to the values of the `min` and
1061
1061
* `max` attributes. When these change in a way that will cause the browser to modify the input value,
@@ -1076,7 +1076,7 @@ var inputType = {
1076
1076
* adds no native HTML5 validation. It also means the browser won't adjust the
1077
1077
* element value in case `min` is greater than the current value.
1078
1078
* @param {string= } ngMax Takes an expression. Sets the `max` validation to ensure that the value
1079
- * entered is less than `max`. Does not set the `min ` attribute and therefore
1079
+ * entered is less than `max`. Does not set the `max ` attribute and therefore
1080
1080
* adds no native HTML5 validation. It also means the browser won't adjust the
1081
1081
* element value in case `max` is less than the current value.
1082
1082
* @param {string= } ngChange Angular expression to be executed when the ngModel value changes due
@@ -1085,25 +1085,24 @@ var inputType = {
1085
1085
* @example
1086
1086
<example name="range-input-directive" module="rangeExample">
1087
1087
<file name="index.html">
1088
- <script>
1089
- angular.module('rangeExample', [])
1090
- .controller('ExampleController', ['$scope', function($scope) {
1091
- $scope.value = 75;
1092
- $scope.min = 10;
1093
- $scope.max = 90;
1094
- }]);
1095
- </script>
1096
- <form name="myForm" ng-controller="ExampleController">
1097
-
1098
- Model as range: <input type="range" name="range" ng-model="value"
1099
- min="{{min}}" max="{{max}}">
1100
- <hr>
1101
- Model as number: <input type="number" ng-model="value"><br>
1102
- Min: <input type="number" ng-model="min"><br>
1103
- Max: <input type="number" ng-model="min"><br>
1104
- value = <code>{{value}}</code><br/>
1105
- myForm.range.$valid = <code>{{myForm.range.$valid}}</code><br/>
1106
- myForm.range.$error = <code>{{myForm.range.$error}}</code>
1088
+ <script>
1089
+ angular.module('rangeExample', [])
1090
+ .controller('ExampleController', ['$scope', function($scope) {
1091
+ $scope.value = 75;
1092
+ $scope.min = 10;
1093
+ $scope.max = 90;
1094
+ }]);
1095
+ </script>
1096
+ <form name="myForm" ng-controller="ExampleController">
1097
+
1098
+ Model as range: <input type="range" name="range" ng-model="value" min="{{min}}" max="{{max}}">
1099
+ <hr>
1100
+ Model as number: <input type="number" ng-model="value"><br>
1101
+ Min: <input type="number" ng-model="min"><br>
1102
+ Max: <input type="number" ng-model="min"><br>
1103
+ value = <code>{{value}}</code><br/>
1104
+ myForm.range.$valid = <code>{{myForm.range.$valid}}</code><br/>
1105
+ myForm.range.$error = <code>{{myForm.range.$error}}</code>
1107
1106
</form>
1108
1107
</file>
1109
1108
</example>
@@ -1113,24 +1112,23 @@ var inputType = {
1113
1112
* @example
1114
1113
<example name="range-input-directive-ng" module="rangeExample">
1115
1114
<file name="index.html">
1116
- <script>
1117
- angular.module('rangeExample', [])
1118
- .controller('ExampleController', ['$scope', function($scope) {
1119
- $scope.value = 75;
1120
- $scope.min = 10;
1121
- $scope.max = 90;
1122
- }]);
1123
- </script>
1124
- <form name="myForm" ng-controller="ExampleController">
1125
- Model as range: <input type="range" name="range" ng-model="value"
1126
- ng-min="10" ng-max="90">
1127
- <hr>
1128
- Model as number: <input type="number" ng-model="value"><br>
1129
- Min: <input type="number" ng-model="min"><br>
1130
- Max: <input type="number" ng-model="min"><br>
1131
- value = <code>{{value}}</code><br/>
1132
- myForm.range.$valid = <code>{{myForm.range.$valid}}</code><br/>
1133
- myForm.range.$error = <code>{{myForm.range.$error}}</code>
1115
+ <script>
1116
+ angular.module('rangeExample', [])
1117
+ .controller('ExampleController', ['$scope', function($scope) {
1118
+ $scope.value = 75;
1119
+ $scope.min = 10;
1120
+ $scope.max = 90;
1121
+ }]);
1122
+ </script>
1123
+ <form name="myForm" ng-controller="ExampleController">
1124
+ Model as range: <input type="range" name="range" ng-model="value" ng-min="min" ng-max="max">
1125
+ <hr>
1126
+ Model as number: <input type="number" ng-model="value"><br>
1127
+ Min: <input type="number" ng-model="min"><br>
1128
+ Max: <input type="number" ng-model="min"><br>
1129
+ value = <code>{{value}}</code><br/>
1130
+ myForm.range.$valid = <code>{{myForm.range.$valid}}</code><br/>
1131
+ myForm.range.$error = <code>{{myForm.range.$error}}</code>
1134
1132
</form>
1135
1133
</file>
1136
1134
</example>
@@ -1594,15 +1592,16 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1594
1592
// IE11 doesn't set the el val correctly if the minVal is greater than the element value
1595
1593
if ( minVal > elVal ) {
1596
1594
element . val ( minVal ) ;
1595
+ elVal = minVal ;
1597
1596
}
1598
- ctrl . $setViewValue ( element . val ( ) ) ;
1597
+ ctrl . $setViewValue ( elVal ) ;
1599
1598
} else {
1600
1599
// TODO(matsko): implement validateLater to reduce number of validations
1601
1600
ctrl . $validate ( ) ;
1602
1601
}
1603
1602
}
1604
1603
1605
- var minAttrType = isDefined ( attr . min ) ? 'min ' : attr . ngMin ? 'ngMin ' : false ;
1604
+ var minAttrType = isDefined ( attr . ngMin ) ? 'ngMin ' : isDefined ( attr . min ) ? 'min ' : false ;
1606
1605
if ( minAttrType ) {
1607
1606
ctrl . $validators . min = isDefined ( attr . min ) && supportsRange ?
1608
1607
function noopMinValidator ( value ) {
@@ -1634,8 +1633,9 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1634
1633
// IE11 doesn't set the el val correctly if the maxVal is less than the element value
1635
1634
if ( maxVal < elVal ) {
1636
1635
element . val ( maxVal ) ;
1636
+ elVal = minVal ;
1637
1637
}
1638
- ctrl . $setViewValue ( element . val ( ) ) ;
1638
+ ctrl . $setViewValue ( elVal ) ;
1639
1639
} else {
1640
1640
// TODO(matsko): implement validateLater to reduce number of validations
1641
1641
ctrl . $validate ( ) ;
0 commit comments