UI Bootstrap's alert message directive is a great module that will take care of displaying all of your application's alert messages. However, I found that it was lacking one important feature - the ability to manage auto-closing of the alerts.
I didn't want my users to always have to manually close the alerts. So, I wrote a simple helper service to add this functionality on top of UI Bootstrap's directive.
First, we have our alert template, which is the standard UI Bootstrap implementation.
My idea was to write a service that manages the alert array outside of UI Bootstrap's directive. This way we can customize how long we want alert messages to stick around for, and create a standard method of adding alerts to our array.
You will first notice, this is not in fact a service. In it's current form it is simply an array and some helper functions on rootScope. This is generally not best practice, but this can easily be moved into a service, directive, or whatever works best for your application.
The key to this abstraction is adding a unique ID to each alert message so we can then find that alert again in the array when we want to destroy it. When we add an alert to the array, we will define how long we want it to stay on screen for.
A simple, clean, and easily customizable to manage alert durations, and possibly more.