If an Angular value update isn't recognized ...

2015-07-01 | #angular, #solution, #webdev

This behaviour mostly stems from value updates inside non-angular handlers like, in my case, an update inside a jQuery iframe-load-handler. Since this happens completely out of Angular's scope the value change isn't recognized correctly although manually triggered on the scope.

The solution for this problem should be to trigger the scope's digest-cycle manually directly after the update inside the handler. So instead of doing

$('iframe').on('load', function(){

$scope.ready = true;

});

You'd have to do

$('iframe').on('load', function(){

$scope.ready = true;

$scope.$apply();

});

There's also $digest() as an alternative to $apply(), which is more concise since it only touches the current scope, but is dicouraged from direct use by Angular. The documentation says: use $apply().