angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

$animate.enabled not being honored on load

Open autumn01 opened this issue 13 years ago • 5 comments

Moving an issue from UI Bootstrap to angular https://github.com/angular-ui/bootstrap/issues/1273#issuecomment-29098018. Following an email trail with @matsko I have decided it might be best addressed here, as it seems more at home on the angular git now.

I have been using the UI Bootstrap carousel as a test and example of this.

I have bee using a "setNgAnimate" directive to dynamically add the enabled / disables state to other directives.

Updated to 1.2.3 still the same issues: http://plnkr.co/edit/UWDcnJ2PGZd474D5SuoS?p=preview

It seams to be working if you enable and then disable the animations again after load. As ng animate disables all animation on load and then enables again when angular is fully initialized i believe setting the disable flag on an element is overridden when the global animations are turned back on.

Even watching the value of $animate.enabled() and triggering "setNgAnimate" doesn't seem to get past this.

autumn01 avatar Dec 02 '13 00:12 autumn01

Hey Matthew.

So, based on the plunkr example, the issue you're running into is that If a directive has a flag that is set to false on bootstrap then the animation will still be enabled after bootstrap and it won't honor what you set for the directive?

Looks like the carousel isn't using $animate here.

matsko avatar Dec 03 '13 00:12 matsko

Hi Matias. That is correct. The carousel has it's own legacy animation code (UI bootstrap have a lot of work to do migrating their directive to bootstrap 3 and angular animations). It is similar enough to trigger angular to recognize it as something it should try animate. In this case i want to be able to tell angular to ignore this directives elements

Notice that even on a basic ng-repeat animation that i can't disable this on load. i have to turn it on then off again to disable the animations. That is the real issue here.

autumn01 avatar Dec 03 '13 00:12 autumn01

Alright cool. I will get to work on this.

matsko avatar Dec 03 '13 01:12 matsko

After spending a couple of hours looking at this, refactoring and thinking of a solution, but then coming back to the conclusion that something is still off.

In your example, on line 55, you're setting the flag to enable and disable on the element itself no?

if (valnew != valold){
  $animate.enabled((valnew === true), $element);
}

If you place a console.log within the if statement you'll see that it never gets called bootstrap. Why? Because the value is false at the start and is undefined yet again afterwards on the next digest. If you place a counter to run the code within the if statement the first time then you notice your code works fine.

//somewhere outside of the watch loop
var count = 0;

//back to that old if statement
if (count++ == 0 || valnew != valold){

Of you can avoid that all together and just do

$animate.enabled(!!valnew, element);

Anyways, have a look with the fix and let me know if there is anywhere else you're experiencing a problem.

matsko avatar Dec 03 '13 03:12 matsko

This is true. I feel a fool, my bad falsy logic. consider this resolved then. All my test are now returning the expected result. Keep up the great work.

autumn01 avatar Dec 03 '13 03:12 autumn01