Angular 4动画正在init组件上执行

时间:2018-05-25 13:55:46

标签: javascript css angular typescript

当执行使用动画的组件时,动画正在执行,同样动画的状态显示为无,

显示这个gif:

Gif

当打开组件时,模态中的动画是appaer,我想要的不是这个。

帮助我,请求!!

component.ts

trigger('openModal', [
  state('true', style({
    display: 'block',
    'transform': 'scale(1)'
  })),
  state('false', style({
    display: 'none',
    'transform': 'scale(0)'
  })),
  transition('* => *', animate('.2s'))
]),

openCancelFavorite: boolean = false;

component.html

 <div [@openModal]="openCancelFavorite" class="onbusca-favorite-remove">
    <div class="row onbusca-row">
      <div class="ml-auto col-auto">
          <i (click)="openCancelFavorite = false" class="fa fa-close onbusca-login-close"></i> 
      </div>
    </div>

      <p class="not-p onbusca-favorite-remove-message">Você tem certeza que quer remover este produto dos favoritos ?</p>

    <div class="onbusca-favorite-buttons">
      <button class="btn btn-primary">Sim, remova</button>
      <button (click)="openCancelFavorite = false" class="btn btn-outline-primary">Cancelar</button>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

我相信你必须将该类的显示默认设置为none。

所以添加display:none; to onbusca-favorite-remove

.onbusca-favorite-remove {
    display: none;
}

否则,您可以在* ngIf上切换动画,如下所示:

将动画更改为:

trigger('openModal', [
state(':enter', style({
    display: 'block',
    'transform': 'scale(1)'
})),
state(':leave', style({
    display: 'none',
    'transform': 'scale(0)'
})),
transition('* => *', animate('.2s'))
]),

openCancelFavorite: boolean = false;

将模板更改为:

<div *ngIf="openCancelFavorite" [@openModal] class="onbusca-favorite-remove"> ... </div>