0

現在のリリースでは、コンポーネントにのみアニメーションを追加でき、ディレクティブとして定義することはできないようです。私は意味:角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、sliddeUp、fadeIn、fadeOutなどのよく使用されるアニメーションをdirとして1か所に定義したいそのコンポーネントを使用したいコンポーネントでは、各コンポーネントのアニメーションを再定義するのではなく、そのディレクティブをインポートしてアニメーションを使用したいだけです。

答えて

0

アニメーションはビュー上で動作し、ディレクティブにはビューがありません。

アニメーションを再利用するにはポイントがありますが、コンポーネントアニメーションメタデータ内のグローバルに定義されたアニメーションによって、コンポーネント内で設定が行われます。

ディレクティブのようなものだが、まったく同じようなものが<div @my-animation="config here...">にも適用されるかもしれないが、これはトリガー状態と重複する。APIはまだ設定されていない。

この号を参照:https://github.com/angular/angular/issues/9668

関連する問題