如果我点击并按住一个按钮,我如何使用angular一次又一次地启动鼠标点击按钮

how can I fire the mouse click button again and again using angular if I click and hold a button?

本文关键字:按钮 何使用 angular 启动 鼠标 一次又一次 如果 一个      更新时间:2023-09-26
    <button type="button" class="btn btn-default"
            ng-click="rotate(true)">
        <i class="fa fa-sort-asc" style="color:blue"></i>
    </button>

在用户点击并按住按钮之前,我如何在间隔500毫秒后一次又一次地调用控制器中的旋转功能?

通过ng mousedown和ng mouseup directie interval服务的组合,您可以创建此功能。

<button type="button" class="btn btn-default"
        ng-mousedown="startRotate(true)" ng-mouseup="endRotate()" ng-mouseleave="endRotate()" >
    <i class="fa fa-sort-asc" style="color:blue"></i>
</button>

在startrotate函数中,您创建了一个间隔,每隔x次调用rotate函数。在endRotate中,您可以按照在start函数中创建的间隔调用cancel函数。

编辑:您还需要ng mouseleave,因为如果您在鼠标按钮按下时将鼠标从按钮上移开,则不会注册ng mouseup。

文件:

http://docs.angularjs.org/api/ng/directive/ngMousedown

http://docs.angularjs.org/api/ng/directive/ngMouseup

http://docs.angularjs.org/api/ng/service/$interval