Ali Yılmaz Ali Yılmaz - 1 year ago 61
AngularJS Question

Ionic - How to get the last value from scrollbar when user removes his hand

I use scrollbar in my app and it works fine, but the problem is the code sends lots of scrollbar values to the server.And it causes some lags.I want to design that so it can send the only last value when user removes his finger from scrollbar.Is it possible ? If so what should I change from my code ?
Thank in advance.Here is my code:
Html part

<div class="item range">
<i class="icon ion-ios7-sunny-outline"></i>
<input type="range" name="volume" min="0" max="100" value="{{scrollvalue}}" ng-model="scrollvalue" ng-change="enter(scrollvalue,">
<i class="icon ion-ios7-sunny"></i>


And here is controller part:


$scope.enter = function(scrollvalue,deviceId,id){

var data2 = {
credentials: $scope.credentials,
//var ss = id;


LightingClient.postLightings(serverUrl, data2, 10000)
.success(function (response) {

Answer Source

What you are looking for is to update your model only when the range input has lost its focus. Add this option to your model:

ng-model-options="{ updateOn: 'blur' }"

 <input type="range" name="volume" min="0" max="100" value="{{scrollvalue}}" ng-model="scrollvalue" ng-model-options="{ updateOn: 'blur' }" ng-change="enter(scrollvalue,">

Another option would be to delay the model update. For example you can set your model to get updated every 1 sec like this:

ng-model-options="{ debounce: 1000 }"

You can read more on ngModelOptions here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download