ng-animate不适用于angularjs 1.1.5中的ng-show

时间:2013-06-25 22:21:37

标签: javascript angularjs ng-animate ng-show

我在最新的angularJS版本1.1.5中测试动画,看起来它无法正常工作。请查看此Fiddle

HTML

<div ng-app>
     <div ng-controller='ctrl'>
        <input type='button' value='click' ng-click='clicked()' />  
        <div ng-show="foo == true"  class='myDiv' ng-animate="{show: 'fadeIn', hide:'fadeOut'}">

        </div>

    </div>
</div>

CSS:

.myDiv{
    width:400px;
    height:200px;
    background-color:red;
}
.fadeIn-setup, .fadeOut-setup {
  -webkit-transition: 1s linear opacity;
  -moz-transition: 1s linear opacity;
  -o-transition: 1s linear opacity;
  transition: 1s linear opacity;
}
.fadeIn-setup{
  opacity:0;
}
.fadeOut-setup{
  opacity:1;
}
.fadeIn-setup.fadeIn-start {
  opacity: 1;
}
.fadeOut-setup.fadeOut-start{
    opacity:0;
}

AngularJS:

function ctrl($scope){
    $scope.foo = false;
    $scope.clicked = function(){
       $scope.foo = !($scope.foo);
    }
}

然而,当我切换回1.1.4版本时,它工作正常但有另一个错误,他们说它已在v1.1.5中修复。现在这令人困惑。他们修复了以前的错误吗?无论如何,任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:5)

所以经过几个小时的挖掘后我找到了解决方案,所有文档都已过时,并且没有更新到最新的API。这是解决方案:

https://github.com/angular/angular.js/commit/11f712bc

根据更改日志:

The CSS transition classes have changed suffixes. To migrate rename:
.foo-setup {...} to .foo {...} 
.foo-start {...} to .foo-active {...}

or for type: enter, leave, move, show, hide:
.foo-type-setup {...} to .foo-type {...} 
.foo-type-start {...} to .foo-type-active {...}