与AngularJS中的jQuery .one()相同的是什么? [英] What's is the equivalent of to jQuery .one() in AngularJS?

查看:58
本文介绍了与AngularJS中的jQuery .one()相同的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个仅触发一次的事件发射器,然后自行破坏。相当于jQuery的.one()函数?

How can you created an event emitter that is only triggered once and self-destructs after that. An equivalent to jQuery's .one() function?

推荐答案

你实际上有一个()可以通过jqLit​​e库在AngularJS中使用。 jsLite是jQuery的简化版本,是为Angular提供支持所需的最低版本。

You actually have one() available to you in AngularJS via the jqLite library. jsLite is an abridged version of jQuery that is the minimum needed to power Angular.

https:// docs.angularjs.org/api/ng/function/angular.element

var e = angular.element(document.querySelector('.myDivClass'));

    e.one('click', function(){
        alert("Only works once!");
    });

Codepen

这篇关于与AngularJS中的jQuery .one()相同的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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