使用angular-ui-bootstrap在显示弹出窗口之前或之后调用回调 [英] Invoking a callback before or after showing a popover using angular-ui-bootstrap

查看:163
本文介绍了使用angular-ui-bootstrap在显示弹出窗口之前或之后调用回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有一个跨度很简单的代码截取器。将鼠标悬停在此范围上会显示一个弹出窗口,我正在使用它来使用angular-ui-bootstrap。

I have a very simple code snipper in my page where I have a span. Hovering over this span displays a popover for which I am using angular-ui-bootstrap.

<span uib-popover="This is a popover from Akhilesh"
              ng-mouseenter="vm.logToConsole('I am trying hard...')"
              popover-trigger="mouseenter">Hover over me to see a popup..!!</span>

基本上,我编写了一个函数,当用户将鼠标悬停在此范围上时,该函数会进行API调用。这里的问题是,假设我在彼此之间有10个span标签,并且用户迅速从第一个span移到了第十个span(在此过程中,鼠标悬停在所有8个span上),API调用将针对所有span被触发。这是我不希望拥有的。

Basically I have written a function which makes and API call when the user hovers over this span. The problem here is that let's say I have 10 span tags one below the other and the user quickly moves from 1st span to 10th span (in the process hovering over all 8 spans in between), the API call will get triggered for all the spans. This is what I do not intend to have.

有什么想法可以在这里实现去抖动功能吗?

Any idea how can I implement the debounce functionality here?

推荐答案

根据您的使用,我发现最好的方法是简单地将ng-mouseover,ng-click等添加到元素并定义要调用的函数。

Depending on your use, I found the best method is to simply add ng-mouseover, ng-click etc to the element and define a function to be called.

您甚至可以动态创建一个变量并将其附加到该对象范围,以跟踪状态(打开关闭)。

You can even create a variable and attach it to that objects scope on the fly to keep track of the state (open close).

有点骇人听闻,但目前无法定义在ui-bootstrap popover中打开和关闭时调用的函数。

Kind of hacky, but there is currently no way to define a function that is called on open and on close within ui-bootstrap popover.

这篇关于使用angular-ui-bootstrap在显示弹出窗口之前或之后调用回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆