Thursday, 15 May 2014

javascript - Change bound angular variable from inside event callback -



javascript - Change bound angular variable from inside event callback -

i'm trying alter input field's value when video loads. here's relevant code:

this works:

$scope.stoprecording = function () { // value of input changes expected $scope.videoendpos = 10; };

this doesn't

$scope.stoprecording = function () { video.onloadedmetadata = function() { $scope.videoendpos = 10; // value of input not change, still correctly outputs 10 console.log($scope.videoendpos); }; };

in effort maintain short left out crucial video stuff there, part working , onloadedmetadata firing properly, funky angular , input. however, allow me know if suspect i've left out relevant code.

the video.stoprecording happens outside of angular universe, not know change. need utilize $scope.$apply, allows execute changes scope outside of angular.

$scope.stoprecording = function () { video.onloadedmetadata = function() { $scope.$apply(function(){ $scope.videoendpos = 10; }); // value of input not change, still correctly outputs 10 console.log($scope.videoendpos); }; };

javascript angularjs

No comments:

Post a Comment