ngAnimate on ngShow. Preventing animation when it starts first time

风格不统一 提交于 2019-11-28 23:27:01

This has been fixed now. Upgrade to 1.1.5.

TheLostBrain

This issue still persists even now with 1.2.22. However, one of these solutions solves it very easily.

After trying all the solutions mentioned here I wanted to specifically highlight cocoggu's suggestion to ac360 as it is by far the most concise and it "just works".

As he suggests, simply adding the ng-hide class to the offending element resolves the problem immediately. - It prevents the initial animation glitch and allows all subsequent animations to behave as expected.

Working Solution thanks to cocoggu

<div id="offending-element" class="ng-hide"></div>

I have found 2 different solutions for your problem

The easiest solution: Add a inline style to the div style="display:none"

The other solution is to add an initial class to the div with ng-class="state" and reset the class when the button is clicked

function ctrl($scope){
    $scope.state = 'hide';
    $scope.foo = false;
    $scope.clicked = function() {
       $scope.state = undefined;  
       $scope.foo = !($scope.foo);
    }
}

together with the following css:

.hide {
    display: none;
} 

I think I would use the first and most simple solution

this should do the trick:

<div ng-class="ng-hide" ng-show="foo == true"  class='myDiv'">

this is the important part here: ng-class="ng-hide"

EDIT: As pointed out in the comments, the above would not work. It should look like this:

<div class="ng-hide" ng-show="foo == true"  class='myDiv'">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!