24

I have this controller and I would like to update the $scope.progress from within the function callback. I tried using $rootScope and $scope.apply() but I can't get it to work. Is there something I'm missing?

progressupdate is a variable returned by the event. the code is not exactly like this. I made it super simple here to show the structure.

app.controller('player', function($scope) {
 var show = function(url) {
 function(err, showOK) {
 if (err) {
 console.log(err);
 } else {
 showOK.on('listening', function(){
 $scope.progress = progressupdate;
 });
 }
 });
 }
 show(url);
});

Am I running that function incorrectly inside the controller? Should I use something like this?

 $scope.show = function(url)...etc
ROMANIA_engineer
57k30 gold badges211 silver badges207 bronze badges
asked Mar 31, 2014 at 19:48
2
  • Your example is syntactically incorrect. Not sure if that's a bad copy/paste or the actual problem. Commented Mar 31, 2014 at 19:52
  • oops, some bad copypasta. Commented Mar 31, 2014 at 19:57

1 Answer 1

35

I don't see the $apply function on above script, and progressupdate. Try $apply after set, or set it inside $apply :

showOk.on('listening', function(){
 $scope.$apply(function(){
 $scope.progress = progressupdate;
 });
});

or

showOk.on('listening', function(){
 $scope.progress = progressupdate;
 $scope.$apply();
});

The first method is recommended.

answered Mar 31, 2014 at 19:53

1 Comment

I guess I'm pretty burned out cause I tried what you suggested before and couldn't get it to work! thanks!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.