3

I have two input types: "range" and "number". If I change the number using the input field, the value is updated in the header and at the range slide. However, I also would like to update the value in my input field, if I change it using the range slide. Right now, only the value in the header is updated.

HTML

<div ng-app>
<div ng-controller="amountController">
     <h2>{{"Amount: " + amount + "$"}}</h2>
    <div class="row">
        <div class="item range" id="index3-rangeAmount"> <i>5000$</i>
            <input type="range" name="volume" min="5000" max="50000" value="{{amount}}" ng-model="amount"> <i>50000$</i>
        </div>
        <div>
            <input type="number" id="index3-inputAmount" min="5000" max="50000" value="{{getAmount()}}" ng-model="amount">
        </div>
    </div>
</div>

Javascript

function amountController ($scope) {
$scope.amount = 7500;
$scope.getAmount = function() {
    return $scope.amount;
};

}

Here is the link to the jsfiddle: jsfiddle

3 Answers 3

4

mate,it's to do with the input type, as your input is number type, but the value you bind is text type, so you can use watch to fix this, have create a fiddle for you, check this:

function MyCont($scope) {
$scope.value = 0;

$scope.$watch('value',function(val,old){
   $scope.value = parseInt(val); 
});
};

http://jsfiddle.net/2e15u0bm/

Sign up to request clarification or add additional context in comments.

Comments

1

Angular doesn't yet support `input type="range".

There is a fix, which will handle range the same as number. It is marked to be fixed in version 1.5-Cadidate. Anyway the issue is open already for quiet a long time. Hope the fix makes it into the next release.

Comments

0

Instead of registering a watcher like Kevin Simple suggested, you could register an on-change (ng-change) method for the input type range like

$scope.valueChanged = function() {
    $scope.amount = parseInt($scope.amount);
}

which will be called by ng-change="valueChanged()":

<input type="range" ng-change="valueChanged()" name="volume" min="5000" max="50000" value="{{amount}}" ng-model="amount"> <i>50000$</i>

Working Fiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.