简体   繁体   English

在AngularJS中单击外部或ESC时如何捕获旁白的关闭事件?

[英]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. 我有一种情况,其中加载了2个辅助对象,并且在关闭辅助对象时必须按ESC或在辅助对象之外单击来清除变量。

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 . 使用v2.1.1的angular-strap$aside的hide事件被更改为aside-hide

The AngularJS framework invokes handlers of $scope/$rootScope events with arguments: AngularJS框架使用参数调用$ scope / $ rootScope事件的处理程序:

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. 使用这些参数获取有关事件的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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