AI Code

Angular 2 Angular2 Animations


Angular's animation system lets you build animations that run with the same kind of native performance found in pure CSS animations. You can also tightly integrate your animation logic with the rest of your application code, for ease of control.

Basic Animation - Transitions an element between two states driven by a model attribute.


    <div *ngFor="let user of users">


import {Component, trigger, state, transition, animate, style} from '@angular/core';

  selector: 'app-root',
  templateUrl: './app.component.html',
  styles: [`
     .btn {
      height: 30px;
      width: 100px;
      border: 1px solid rgba(0, 0, 0, 0.33);
      border-radius: 3px;
      margin-bottom: 5px;

  animations: [
    trigger('buttonState', [
      state('true', style({
        background: '#04b104',
        transform: 'scale(1)'
      state('false',   style({
        background: '#e40202',
        transform: 'scale(1.1)'
      transition('true => false', animate('100ms ease-in')),
      transition('false => true', animate('100ms ease-out'))
export class AppComponent {
  users : Array<User> = [];
    this.users.push(new User('Narco', false));
    this.users.push(new User('Bombasto',false));
    this.users.push(new User('Celeritas', false));
    this.users.push(new User('Magneta', false));

export class User {
  firstName : string;
  active : boolean;

  changeButtonState(){ = !;
  constructor(_firstName :string, _active : boolean){
    this.firstName = _firstName; = _active;


Got any Angular 2 Question?