2

I am using $interval for my custom stopwatch. Within the $interval function I have a variable $scope.inputValue which is binded to a range. The problem is that after each iteration of $interval (every 500ms), the most recent $scope.inputValue is not taken into account, but only the value at the initialization (1000).

How to solve this?

Controller

.controller('DashCtrl', function($scope, $interval) {

    var interval, incrementTimer;

    $scope.inputValue       = 1000;

    //
    //
    incrementTimer = function() {
        userValue = $scope.inputValue; 
        console.log(userValue); // does not update when range changes
    };


    //
    // button toggle
    $scope.toggleTimer = function() {
        interval = $interval(incrementTimer, 500);
    };

})

HTML

<input type="range" min="0" max="2000" step="100" ng-model="inputValue">

<button class="button button-positive" ng-click="toggleTimer()">Start</button>
9
  • 1
    Where are you calling $scope.toggleTimer()?
    – devqon
    Jun 22, 2015 at 14:43
  • @devqon in my html, on a button click (I have updated the question).
    – WJA
    Jun 22, 2015 at 14:45
  • try logging $scope.inputValue inside of incrementTimer, do you get the correct result?
    – ajmajmajma
    Jun 22, 2015 at 14:48
  • @ajmajmajma no, it just stays the same value (1000), despite me changing the range (even when I change it before I initiate toggleTimer())
    – WJA
    Jun 22, 2015 at 14:49
  • 1
    The problem is probably not using a dot in ng-model. If it is the case, then there may be an inherited scope being created by a parent node which contains the HTML you posted. Posting some more context around it will help in debugging it. Jun 22, 2015 at 14:58

2 Answers 2

1

The problem is probably not using a dot in ng-model. There probably is an inherited scope being created by a parent node which contains the HTML posted in the question.

See also:

1

For me, the problem was probably about the dot thingy you all spoke about. However, I needed to remove announcement on the controller:

<ion-view view title="bla bla" ng-controller="tabletStayInTouchCtrl" on-touch="onTouch()"> 

Had to be changed to this:

<ion-view view title="bla bla"  on-touch="onTouch()"> 

I guess it is all about the parental-controller that caused the problem.

Your Answer

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

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