Angular factory for executing $apply safely on the scope.