Check new msg and create header badge in all view


I firends, I’m create a controller to check new message and add badge in side menu.

So the controller is associated to the side menu.
Now, with the same code, I would add badge to the right sidemenu button in the header when the user receive new message in all view of the app!

This is my controller js now for sidemenu:

var user_id = $localstorage.get('user_id');
var timer;
function myLoop(){
    timer = $timeout(function(){console.log( "Timeout executed")},5000);
                function(){$''+user_id).success(function(data){if(data!=0){$scope.counter = data}}).error(function(){alert("Errore di comunicazione!")});myLoop()},
                function() {console.log("Timer rejected!")}
$scope.$on("$destroy", function(event) {$timeout.cancel( timer )});