What's the best way to force a digest in Angular when using events outside of Angular itself - for example when loading an image in a jqLite container, I find myself doing this:
$img.on('load', function () {
$timeout(function () { // Force digest
$scope.isLoaded = true;
});
});
This is a pattern I find myself using a lot. However it feels very dirty (like a hack-dirty, ugh). However, using $apply()
might trigger a "digest already in progress" error. I know I could check for $scope.$$phase
, but that feels equally dirty.
So, what's the correct way to get your changes to the DOM as fast as possible?