Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I apply a CSS class within an Angular 2 animation state?

Tags:

angular

I am attempting to utilize Angular 2's animation facilities and I've discovered that I can't seem to be able to set a CSS class associated with a state, and I instead must hard code style values, like so:

@Component({
  animations: [
    trigger('responseState', [
      state('default', style({
        color: '#31708f',
        backgroundColor: '#d9edf7',
        borderColor: '#bce8f1'
      })),
      state('success', style({
        color: '#3c763d',
        backgroundColor: '#dff0d8',
        borderColor: '#d6e9c6'
      })),
      state('error', style({
        color: '#a94442',
        backgroundColor: '#f2dede',
        borderColor: '#ebccd1'
      })),
      transition('default <=> success', animate('500ms ease-in')),
      transition('default <=> error', animate('500ms ease-in')),
      transition('error <=> success', animate('500ms ease-in'))
    ])
  ]
})

What I was hoping to do would be something like:

@Component({
  animations: [
    trigger('responseState', [
      state('default', style({
        class: '.default-state'
      })),
      state('success', style({
        class: '.success-state'
      })),
      state('error', style({
        class: '.error-state'
      }))
    ])
  ]
})

Can anyone let me know if this is possible?

like image 678
cjones26 Avatar asked Aug 22 '17 21:08

cjones26


People also ask

How do you define transition between two states in Angular?

In Angular, transition states can be defined explicitly through the state() function, or using the predefined * (wildcard) and void states.

What is the benefit of Angular animation?

You can control the timing of each transformation. Angular's animation system is built on CSS functionality, which means you can animate any property that the browser considers animatable.

Which of the following are valid easing functions in Angular animations?

The easing value controls how the animation accelerates and decelerates during its runtime. Value is one of ease , ease-in , ease-out , ease-in-out , or a cubic-bezier() function call. If not supplied, no easing is applied.

Which animation strategy would you use if there were multiple animations that had to occur at the same time?

To create a staggered animation, use multiple Animation objects. One AnimationController controls all of the Animation s. Each Animation object specifies the animation during an Interval .


1 Answers

As far as I know, this is not possible. The angular animations API seems to still be pretty limited from my experience playing around with it. The only thing I've been consistently using it for is applying animations/transitions to elements that have unpredictable / varying heights. I still use standard CSS3 animations and transitions for nearly all my angular code.

like image 161
diopside Avatar answered Sep 28 '22 22:09

diopside