问题描述
限时送ChatGPT账号..是否有指令或方法可以在 AngularJS 中实现 .one() 函数实现的功能用jQuery?
即将事件附加到只执行一次的元素上.
解决方案将 ng-click 连接到您想要的元素,然后在控制器的 ng-click 函数中有一个变量,您可以将其切换到一个状态使 ng-click 不再执行类似
var fireOnce = false;scope.myClickFunction = function(){if(firedOnce){ 返回;}//其他代码发射一次 = 真;}
您也可以连接一个指令来执行此操作.
编辑:指令方法的jsfiddle:http://jsfiddle/4hDb3/>
Is there a directive or a way to implement in AngularJS what .one() function achieves with jQuery?
i.e., to attach an event to an element that gets executed only once.
解决方案Wire up an ng-click to the element you want, then in the ng-click function in your controller have a variable that you toggle to a state that would make the ng-click no longer execute something like
var firedOnce = false;
scope.myClickFunction = function(){
if(firedOnce){ return; }
//other code
firedOnce = true;
}
You could also wire up a directive to do it too.
edit: Jsfiddle of directive method: http://jsfiddle/4hDb3/
这篇关于只执行一次的事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论