0

I want to access and update state of variable.

function valueChange(sourceVariable, targetVariable, sourceUnit) {
    $scope[targetVariable] = measure($scope[sourceVariable] + sourceUnit + ".").kilograms();        
}); 

This function is called whenever something is entered in input field (on tab out). But the problem is value in input field that is bound to $scope[targetVariable] is not updated until you click inside input box.

PS: If I use variable in regular fashion it works fine.

2
  • Can you attache a jsbin sample or html update question with html part where you bind $scope[targetVariable] with input? Commented Oct 15, 2016 at 7:25
  • <input ng-model="details.model.NetWeightImperial" ng-model-options="{ updateOn: 'change blur', debounce: 0 }" type="text"> Commented Oct 15, 2016 at 7:33

1 Answer 1

1

You probably need to udpate your variable inside $scope.$apply:

function valueChange(sourceVariable, targetVariable, sourceUnit) {
    $scope.$apply(function() {
          $scope[targetVariable] = measure($scope[sourceVariable] + sourceUnit + ".").kilograms();      
    });  
}); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the idea, i had error with variable names also.

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.