How an event can be expired or disappeared by any other event

var foo = new function(){
$scope.MessageSpan="Item added successfully";}

      

The above function is called when the Add button is clicked for example. Now, for any other button press. If I want to hide this message, I need to update the range text in all other buttons on the page, but this is too much.

So, once the field is filled with "Item added successfully", can the text in this span be automatically updated / removed when I click on any other event? Instead of making it explicit?

thank

+3


source to share


1 answer


You can create a directive that will display your message, then set up an event listener for the click on $window

and unregister that listener when you click anything.

Sketch:



var handler = function(){
    $scope.MessageSpan = undefined; 
    angular.element($window).off('click',handler)
};
$scope.MessageSpan = "Item added successfully";
angular.element($window).on('click', handler);

      

+1


source







All Articles