Check new msg and create header badge in all view


#1

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);
            timer.then(
                function(){$http.post('http://www.digitalxp.it/appwork/include/check_msg.asp?id='+user_id).success(function(data){if(data!=0){$scope.counter = data}}).error(function(){alert("Errore di comunicazione!")});myLoop()},
                function() {console.log("Timer rejected!")}
            );
}
myLoop();            
$scope.$on("$destroy", function(event) {$timeout.cancel( timer )});