Add condition to avoid triggering $digest unnecessarily