17

I am trying to use Angular2 animation system, for a pseudo element :before. As per animation flow, I need to define animation state:

animations: [
trigger('heroState', [
  state('inactive', style({
    backgroundColor: '#eee',
    transform: 'scale(1)'
  })),
  state('active',   style({
    backgroundColor: '#cfd8dc',
    transform: 'scale(1.1)'
  })),
  transition('inactive => active', animate('100ms ease-in')),
  transition('active => inactive', animate('100ms ease-out'))
])]

and then attach it to a DOM element, as follows:

<ul>
<li *ngFor="let hero of heroes"
    [@heroState]="hero.state"
    (click)="hero.toggleState()">
  {{hero.name}}
</li>

However, I want to attach this to a pseudo before element. How can I do that?

Lucas
  • 9,871
  • 5
  • 42
  • 52
Yuvals
  • 3,094
  • 5
  • 32
  • 60
  • I'm wonder if CSS ::before and ::after ares something you could do with [ngClass] per here: https://cssanimation.rocks/pseudo-elements/ The fact it says it inserts pseudo-elements makes me wonder if it'll work. No idea though if you can combine with the angular animations. Nice question. – JGFMK Aug 01 '17 at 12:43
  • As far as my knowledge this feature is not available. There is a feature request for this. https://github.com/angular/angular/issues/10196. But you can achive this by adding an element like span instead of going for pseudo. I know your requirement is through pseudo element but since its not present. – rajesh Aug 04 '17 at 12:50

1 Answers1

1

Try this please this will what you want.

<style>
h1::before {
    content: url(animation.html);
}
</style>

animation.html file

<ul>
<li *ngFor="let hero of heroes"
    [@heroState]="hero.state"
    (click)="hero.toggleState()">
  {{hero.name}}
</li>

Hope this works for you.

More about this Using Javascript in CSS

Sergey
  • 73
  • 9