Using $timeout instead of $scope.$apply()
AngularJS automatically detects model changes inside AngularJS event handlers. However, when changes occur outside the AngularJS execution context (e.g., in event listeners, setTimeout, AJAX calls, or third-party libraries), AngularJS does….
