Changed from scope.$digest() to scope.$apply() as suggested in the angular documentation.