D
D
Drovosek012018-08-09 01:21:04
Angular
Drovosek01, 2018-08-09 01:21:04

Why are styles reset after animation in Angular?

Animating the search bar with Angular animation and ngIf.
After an input appears, when its input animation times out, the applied styles are reset. Why is this happening and how to fix it?
Sample code here: https://stackblitz.com/edit/angular-3ug5j7?file=ap...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-08-09
@Drovosek01

You've specified the state to transition to instead of styling the element itself properly. Either enter the applied width directly in the css, or specify it as a wildcard. Should it be something like this ?

D
Dmitry Luzanov, 2018-08-09
@dmitry_luzanov

Specify width: '*' for the animation result. And in css set the desired width.

trigger('fadeInOut', [
      transition(':enter', [style({
        width: '59px',
        border: 'none',
      }),
        animate(3000, style({
          width: '*',
          border: 'solid 1px #ebebeb',
        }))],
      ),
      transition(':leave', [
        animate(3000, style({
          width: '59px',
          border: 'none',
        }))],
      ),
    ])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question