I found this code snippet which is part of a angular directive someone wrote for bootstrap modal.
//Update the visible value when the dialog is closed
$$phase is a flag set while angular is in a $digest cycle.
$$phase
$digest
Sometimes (in rare cases), you want to check $$phase on the scope before doing an $apply. An error occurs if you try to $apply during a $digest:
$apply
Error: $apply already in progress