2015-06-02 32 views
0

我使用angularJS與AngularUI API來顯示。如何動畫裏面的指令崩潰使用NG-如果到

我的問題是,當我使用包含崩潰一個指令。

會發生什麼:

我的指示正確初始化,但不動畫當我設置崩潰假,我需要動畫。

我的模板使用指令:

<div ng-if="showDirective"> 
    <my-form></my-form> 
</div> 

我的指令:

angular.module('app') 
    .directive('myForm', MyForm); 

function MyForm() { 
     return { 
      controllerAs: 'gr', 
      restrict: 'E', 
      replace: false, 
      templateUrl: 'myForm.html', 
      scope: { 
       cancel: '&?', 
      }, 
      link:link, 
      controller: controller, 
     } 

     function link(scope, element, attrs, ctrl){ 
      angular.element(document).ready(function(){ 
      ctrl.isCollapse = false; 
      }); 
     } 

     function controller($scope) { 
      var vm = this; 
      vm.isCollapse = true; 
     } 
    } 
})() 

我的指令模板:

<div> 
    <div collapse="gr.isCollapse"> 
     //A lot of code.... 
    </div> 
</div> 
+0

你應該看看$ ngAnimate模塊https://docs.angularjs.org/api/ngAnimate – edrian

回答

1

明白了!

function link(scope, element, attrs, ctrl){ 
    $timeout(function(){ 
    ctrl.isCollapse = false; 
    }, 0); 
} 

指令後負荷因此崩潰工作:

我只設置使用$超時 isCollapsed爲false。