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 likevar 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.net/4hDb3/ 这篇关于仅执行一次的事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-24 16:24