$ animate.enter()在自定义指令的元素上

时间:2014-07-18 19:19:21

标签: angularjs angularjs-directive

我正在尝试在我的自定义指令中使用$ animate.enter()来显示/隐藏指令所定义的相同元素,如下所示,但它不起作用。 “离开”功能工作正常。

思想?

var myApp = angular.module('myApp',['ngAnimate']);

myApp.directive('hideMe', function($animate, $timeout){
    function fnLink(scope, element, attrs){ 
        $timeout(function(){
           $animate.leave(element);
        }, 2000);

        $timeout(function(){
           $animate.enter(element, element.parent());
        }, 5000);
     };

    return {        
        link: fnLink
    };
});

[编辑] 这是一个小提琴:http://jsfiddle.net/6P6qM/

1 个答案:

答案 0 :(得分:1)

console.log()方法之前调用$animate.enter()会向您显示element.parent()为空,这是正常的,因为该元素先前已由{{1}与DOM分离方法。

解决方案是在分离元素之前保存父级。不要忘记下次打开你的控制台!

$animate.leave()
相关问题