当值超过 100 时,如何使用 AngularJS 初始化 input[range] 的值

mpr*_*net 0 javascript input range angularjs angularjs-directive

我尝试使用 AngularJS 初始化滑块,但是当值超过 100 时光标显示 100。

在 [50,150] 范围内设置值 150 失败,代码如下:

<html ng-app="App">
<head>
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
	<script>
		angular.module('App', ['App.controllers']);
		angular.module('App.controllers', []).controller('AppController', function($scope) {
			$scope.min = 50;
			$scope.max = 150;
			$scope.value = 150;
		});		
	</script>
</head>
<body ng-controller="AppController" >
	{{min}}<input ng-model="value" min="{{min}}" max="{{max}}" type="range" />{{max}}<br/>
	value:{{value}}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

光标放置不当(显示 100 而不是 150)。如何将光标显示到正确的位置?

对发生的事情的解释可以在这个论坛上

更新
此错误报告为问题#6726

更新
问题#14982被拉请求 14996关闭并解决问题,请参阅答案

mpr*_*net 5

经过搜索和尝试,一种可能的方法是定义自定义指令:

<html ng-app="App">
<head>
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
	<script>
		angular.module('App', ['App.controllers']);
		angular.module('App.controllers', []).controller('AppController', function($scope) {
			$scope.min = 50;
			$scope.max = 150;
			$scope.value = 150;
		}).directive('ngMin', function() {
			return {
				restrict: 'A',
				require: 'ngModel',
				link: function(scope, elem, attr) { elem.attr('min', attr.ngMin); }
			};
		}).directive('ngMax', function() {
			return {
				restrict: 'A',
				require: 'ngModel',
				link: function(scope, elem, attr) { elem.attr('max', attr.ngMax); }
			};
		});		
	</script>
</head>
<body ng-controller="AppController" >
	{{min}}<input ng-model="value" ng-min="{{min}}" ng-max="{{max}}" type="range" />{{max}}<br/>
	value:{{value}}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

即使它正在工作,这也是一个非标准的扩展,以便管理一个非常基本的用例。