Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give class name to animation state in angular 2/4?

I am using angular Animations with version 4.1.3

Here is the below code:

@Component({
  selector : 'my-fader',
  animations: [
    trigger('visibilityChanged', [
      state('true' , style({ opacity: 1, transform: 'scale(1.0)' })),
      state('false', style({ opacity: 0, transform: 'scale(0.0)'  })),
      transition('1 => 0', animate('300ms')),
      transition('0 => 1', animate('900ms'))
    ])
  ]
...

Now, instead of style in state I would like to give existing class name i.e using the class defined in style sheets (i.e Not inline styles)

Is that possible? If so please help.

like image 553
sudhir Avatar asked Sep 07 '17 13:09

sudhir


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.

Does Angular 4 include animation module?

Animations add a lot of interaction between the html elements. Animation was also available with Angular2. The difference with Angular 4 is that animation is no more a part of the @angular/core library, but is a separate package that needs to be imported in app. module.

What is a class in animate?

Definition: An animate class is a category of nouns having human or animal referents. Discussion: In some languages, the animate class is a grammaticalized noun class. Noun.


1 Answers

You can't. I was also looking for a similar solution.

Angular Animations use the Web Animations API and not CSS.

See https://css-tricks.com/css-animations-vs-web-animations-api/ for further reading.

like image 120
user1059939 Avatar answered Sep 21 '22 19:09

user1059939