简体   繁体   English

AngularJS的可重复动画

[英]Repeatable animation with AngularJS

I'm using a custom directive to trigger an animation on an element when a specified field is blank on the page. 当页面上的指定字段为空白时,我正在使用自定义指令来触发元素上的动画。 As of now when a user clicks the button with my custom directive the animation will work, once. 到目前为止,当用户单击带有我的自定义指令的按钮时,动画将起作用一次。 Clicking the button again will not fire the animation and I'm not sure why. 再次单击该按钮将不会触发动画,我不确定为什么。 I have attempted to use .then() with the $animate service however no luck. 我尝试将.then()与$ animate服务一起使用,但是没有运气。

Thanks in advance for any/all assistance. 在此先感谢您提供的任何/所有帮助。

 (function () { 'use strict' ice.directive('cfWobbler', ['$animate', '$parse', cfWobbler]) function cfWobbler($animate, $parse) { var ret = { restrict: 'A', link: link } return ret; function link(scope, elem, attrs) { var el = document.getElementById('division-holder'); var fn = $parse(attrs['cfWobbler']); elem.on('click', function () { scope.$apply(function () { if (fn(scope) === '') { $animate.removeClass(el, 'bounceInDown'); debugger; $animate.addClass(el, 'wobbler', function () { $animate.removeClass(el, 'wobbler') }); } }); }); } } })(); 

I got it working however I have an error in my console. 我可以正常工作,但是控制台中有错误。 I know I've committed a big "No No" as far as Angular but I am not sure how else to do it. 我知道我已经对Angular做出了很大的“不反对”的决定,但是我不确定还有其他方法。

Here is the error in my console. 这是我的控制台中的错误。

Error: [$rootScope:inprog] $apply already in progress 错误:[$ rootScope:inprog] $ apply已在进行中

Here's my working code. 这是我的工作代码。

 (function () { 'use strict' ice.directive('cfWobbler', ['$animate', '$parse', cfWobbler]) function cfWobbler($animate, $parse) { var ret = { restrict: 'A', link: link } return ret; function link(scope, elem, attrs) { var el = document.getElementById('division-holder'); var fn = $parse(attrs['cfWobbler']); elem.on('click', function () { scope.$apply(function () { if (fn(scope) === '') { debugger; $animate.removeClass(el, 'bounceInDown'); $animate.removeClass(el, 'wobbler'); scope.$apply(); $animate.addClass(el, 'wobbler'); } }); }); } } })(); 

Got it working, sans error(s) in the console. 正常运行,没有控制台中的错误。

 (function () { 'use strict' ice.directive('cfWobbler', ['$animate', '$parse', cfWobbler]) function cfWobbler($animate, $parse) { var ret = { restrict: 'A', link: link } return ret; function link(scope, elem, attrs) { var el = document.getElementById('division-holder'); var fn = $parse(attrs['cfWobbler']); elem.on('click', function () { scope.$apply(function () { $animate.removeClass(el, 'bounceInDown'); $animate.removeClass(el, 'wobbler'); }); scope.$apply(function () { if (fn(scope) === '') { $animate.addClass(el, 'wobbler'); } }); }); } } })(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM