这可能是因为 Angular 还没有实现处理程序,type="range"
就像它对type="number"
, 等所做的那样。你可能应该在他们的 Github 网站上报告这个(在问题下)。
同时,您可以像这样绕过它。也就是说,创建您自己的range-model
并添加一个解析器ngModelController
,将值转换为数字。
<!doctype html>
<html ng-app="myApp">
<head>
<script src="http://code.angularjs.org/1.0.5/angular.min.js"></script>
<script>
angular.module('myApp', []).controller('Ctrl', function($scope) {
$scope.age = 10;
$scope.retirementAge = 65;
})
.directive('rangeModel', function() {
return {
require: 'ngModel',
link: function($scope, elem, attrs, ctrl) {
ctrl.$parsers.push(function(val) {
return parseInt(val, 10);
});
}
};
});
</script>
</head>
<body ng-controller="Ctrl">
<input type='range' min='15' max='{{retirementAge - 1}}' range-model name='age' ng-model='age' />
{{age}}
<input type='range' min='{{age + 1}}' max='90' name='retirementAge' range-model ng-model='retirementAge' />
{{retirementAge}}
</body>
</html>