1

I am using angularjs to stop range slider at 75 but its not a good way. Can some body guide me how to do it? [EDIT to clarify after max=75 answer] Remember I do want to show total 100 or maximum scale but still want to limit to 75 percent or at 75.

<html ng-app="root">
<body>
    <div ng-controller="index">{{message}}
        <input type=range ng-model="data.sl" id=sl />
        <input type=text ng-model="data.sl" />
    </div>
</body>
</html>
<script src="angular.js"></script>

angular.module('root', [])
.controller("index", ["$scope", function ($scope) {
    $scope.message = "Hello World!";
    $scope.data = {};
    $scope.data.sl = 12;
    $scope.$watch('data.sl',function(nv,ov){
        if(nv==ov)return;

        if(nv >= 75){
            document.getElementById("sl").stepDown(10);
            console.log("going up");
        }
    });
}]);

3
  • 4
    <input type="range" max="100"> Commented Mar 26, 2015 at 15:21
  • ^there you go thats all
    – user4433485
    Commented Mar 26, 2015 at 15:22
  • No I do want to show the maximum value of 100 but still stop at 75! Commented Mar 26, 2015 at 17:34

2 Answers 2

1

Just use the max attribute to limit the maximum value of the range input. Like so:

<input type="range" value="0" max="75">

For more information you can use check out MDN's documentation about the input element.

1
  • 2
    No I do want to show the maximum value of 100 but still stop at 75! I am not so much newbie :) Commented Mar 26, 2015 at 17:29
0

Here I go:

    $scope.$watch('data.sl',function(nv,ov){
    if(nv==ov)return;

    if(nv >= 75){
        //document.getElementById("sl").stepDown(10);
        $scope.data.sl=75;
        console.log("going up");
    }
    if(nv <= 25){
        //document.getElementById("sl").stepDown(10);
        $scope.data.sl=25;
        console.log("going down");
    }
});

Not the answer you're looking for? Browse other questions tagged or ask your own question.