0

I'm running a jQuery animation, after which I need to update the value of the data inside the animated element.

For some reason I cannot do this

$scope.myVar = "START";

$("#div").delay(100).animate({
    top: '50px'
}, {
    duration: $scope.speed,
    easing: $scope.ease,
    complete: function () {
        $scope.myVar = "FINISHED";
    }
});

When logging the variable it does update; however, this is not reflected on screen.

2 Answers 2

3

You will need to use $scope.apply. From angular documentation

$apply() is used to execute an expression in angular from outside of the angular framework. (For example from browser DOM events, setTimeout, XHR or third party libraries)

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

1 Comment

Thanks for the (very) quick reply. It seems a novice question so hope it helps someone else out.
1

I usually use $timeout:

$timeout(function () {
  //$scope.myvar = "FINISHED";
}, 0);

it works but I don't know how much it's elegant...

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.