According to the latest angular 2 documentation, you can animate the input and output elements (as in angular 1).
An example of a simple fade animation:
In the corresponding @Component add:
animations: [ trigger('fadeInOut', [ transition(':enter', [ // :enter is alias to 'void => *' style({opacity:0}), animate(500, style({opacity:1})) ]), transition(':leave', [ // :leave is alias to '* => void' animate(500, style({opacity:0})) ]) ]) ]
Do not forget to add import
import {style, state, animate, transition, trigger} from '@angular/animations';
The corresponding HTML element of the component should look like this:
<div *ngIf="toggle" [@fadeInOut]>element</div>
I created an example slide animation here .
Explanation on "void" and "*":
void is the state when ngIf set to false (it applies when the element is not attached to the view).* - There can be many animation states (more in the documentation). The * state takes precedence over all of them as a "wildcard" (in my example, this is the state when ngIf set to true ).
Note (taken from angular docs):
Additional declaration inside the application module, import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
Angular animations are built on top of the standard web animation APIs and run natively in browsers that support it. For other browsers, polyfill is required. Take web-animations.min.js from GitHub and add this to your page.
Asaf Hananel Sep 06 '16 at 19:04 2016-09-06 19:04
source share