I'm currently working on a project where I need to show error messages from the $exceptionHandler factory for 5 seconds before they disappear. In order to achieve this, I created a view with the following code:
<div class="messages">
<div class="message" ng-repeat="message in errors">
{{message}}
</div>
</div>
Here is the relevant part of the factory as well:
services.factory('$exceptionHandler',function ($injector) {
return function(exception, cause) {
var $rootScope = $injector.get('$rootScope');
$rootScope.errors = $rootScope.errors || [];
$rootScope.errors.push(exception.message);
setTimeout(function(){
$rootScope.errors.splice(0,1);
}, 5000);
};
});
Although the error messages were being displayed correctly, I noticed that even after removing them from the array, they were still visible on the view. It seems like I might need to utilize $digest and $apply, but I'm not sure how to implement this. Any assistance would be greatly appreciated!