Skip to content Skip to sidebar Skip to footer

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?

Solution 1:

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


Post a Comment for "What's Is The Equivalent Of To JQuery .one() In AngularJS?"