Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's is the equivalent of to jQuery .one() in AngularJS?

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

like image 629
Knights Avatar asked Nov 21 '25 00:11

Knights


1 Answers

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!");
    });

Example on Codepen

like image 127
cpk Avatar answered Nov 22 '25 13:11

cpk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!