2016-07-10 34 views
0

似乎在當前版本中,我們只能將動畫添加到組件,並且不能將它們定義爲指令。我的意思是:Angular 2 RC 4指令中不支持的新動畫

下面的工作

@Component({ 
    selector: "animate-demo", 
    animations: [ 
     trigger('openClose', [ 
      state('closed, void', 
       style({ height: "0px" })), 
      state('open', 
       style({ height: "*" })), 
      transition("* => *", animate(200)) 
     ]) 

儘管低於不起作用:

@Directive({ 
    selector: "animate-demo", 
    animations: [ 
     trigger('openClose', [ 
      state('closed, void', 
       style({ height: "0px" })), 
      state('open', 
       style({ height: "*" })), 
      transition("* => *", animate(200)) 
     ]) 
    ] 
}) 

並給出編譯錯誤,在Visual Studio:

"Argument of type '{ selector: string; animations: AnimationEntryMetadata[]; template: string; }' is not assignable to parameter of type '{ selector?: string; inputs?: string[]; outputs?: string[]; properties?: string[]; events?: strin...'. 

平時我們可能想要將常用動畫(如slideDown,slidingdeUp,fadeIn,fadeOut)定義在一個位置作爲目錄然後在我們想要使用它們的組件中,我們只想導入指令並使用動畫,而不是在每個組件中重新定義動畫。

回答

0

動畫在視圖上工作,指令沒有視圖。

您需要重複使用動畫有一點,但它將通過在組件動畫元數據中設置全局定義的動畫在組件中完成。

它可能會被應用到HTML語法中,類似於指令,但不完全是,<div @my-animation="config here...">,但這會與觸發器狀態重疊... API尚未設置。

查看本期:https://github.com/angular/angular/issues/9668