简体   繁体   中英

How to capture the closing event of an aside when clicked outside or ESC in AngularJS?

I have a case where in which 2 asides are loaded and I have to clear a variable when the aside is closed pressing ESC or by clicking outside the aside.

I searched online and found that the following code can be used in the case of a modal. What is the code for aside?

scope.$on('modal.hide', function() {
      console.log('modal... -hide');
    });

How to watch for an Aside closing in angular-strap

The above code is not working for aside.

  1. Is this approach correct? Otherwise, please suggest a method.

  2. In the above case the modal name is not specified. So when we have more than one modal or aside how do we differentiate the closing of the modal or aside? In the current case, I don't have to differentiate the modals. But how to catch the event differently?


Update

The following code woks for aside.

scope.$on('aside.hide', function() {
    console.log('aside... -hide');
}); 

The second question of how to identify each aside closing differently needs to be found out now.

With v2.1.1 of angular-strap the hide event for $aside was changed to aside-hide .

The AngularJS framework invokes handlers of $scope/$rootScope events with arguments:

scope.$on('aside.hide', function(event, data) {
    console.log('aside... -hide');
    console.log(event);
    console.log(data);
});

Use those arguments to get information about the event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM