1

I want to make the animations to use a variable from the component and not hardcoding the hex color. How can I do it? I need to mention that I really need this because in future I want to create randomly colors so I need to get this colors from a variable. This is my code:

@Component({
  selector: 'app-demo',
  templateUrl: './demo.component.html',
  styleUrls: ['./demo.component.css'],
  animations: [
    trigger('heroState', [
      state('inactive', style({
        backgroundColor: '#eee'
        // transform: 'scale(1)'
      })),
      state('active',   style({
        backgroundColor: '#ff0000'
        // something like this
        // backgroundColor: this.color;
        // transform: 'scale(1.1)'
      })),
      transition('inactive => active', animate('100ms ease-in')),
      transition('active => inactive', animate('1000ms ease-out'))
    ])
  ]
})
export class DemoComponent implements OnInit {

  color:string = "#ff0000";

  inactive: boolean = false;

  constructor() { }

  ngOnInit() {
  }

  get stateName() {
    return this.inactive ? 'inactive' : 'active';
  }

  toggle() {
    this.inactive = !this.inactive;
  }
}
Miguel Barra
  • 769
  • 1
  • 5
  • 7
  • see https://stackoverflow.com/a/46003758/1112003 – Jscti May 02 '18 at 13:03
  • 2
    Possible duplicate of [Parameter in to Animation Angular2](https://stackoverflow.com/questions/41966673/parameter-in-to-animation-angular2) – Diasiare May 02 '18 at 13:19

0 Answers0