当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - how an event can be expired or disapear by any other event

问题描述:

var foo = new function(){

$scope.MessageSpan="Item added successfully";}

The above function is called when clicking on Add button for example. Now, for any other button click, If I want to hide this message, I have to update the span text in all other buttons in the page, but that is too much work.

So, once the span is filled with "Item added successfully", can the text at that span be automatically updated/removed when I click on any other event? Instead of doing that explicit?

Thank you

网友答案:

You can create directive which will display your message, then will set event listener for mouse click on $window, and unregister this listener when you click something.

Sketch:

var handler = function(){
    $scope.MessageSpan = undefined; 
    angular.element($window).off('click',handler)
};
$scope.MessageSpan = "Item added successfully";
angular.element($window).on('click', handler);
分享给朋友:
您可能感兴趣的文章:
随机阅读: