首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular2动画不适用于ngIf

Angular2动画不适用于ngIf
EN

Stack Overflow用户
提问于 2016-10-13 06:08:54
回答 1查看 2.2K关注 0票数 1
代码语言:javascript
复制
<div *ngIf="clientTable" [@clientTableState]="testAnimate.state" class="clientdata">
  <div class="table-holder">
    <table id="header-fixed"><a (click)="closeClientTable()" class="table-close"><i class="ion-close-circled"></i></a>
      <tr>
        <th colspan="8">{{ clientTableHeader }}</th>
      </tr>
      <tr>
        <th rowspan="2">Bookie</th>
        <th colspan="3">Payment</th>
        <th colspan="3">Bookie</th>
        <th rowspan="2">Balance</th>
      </tr>
    </table>
  </div>
</div> 

@Component({
  templateUrl: 'app/html-templates/bookiedata.html',
  styleUrls: ['css/templates.css'],
  animations: [
    trigger('clientTableState', [
        state('inactive', style({
            opacity: 0
        })),
        state('active', style({
            opacity: 1
        })),
        transition('inactive => active', animate('0.8s ease-in-out')),
        transition('active => inactive', animate('0.8s ease-in-out'))
    ])
  ]
})

切换状态法

代码语言:javascript
复制
// declaration
clientTable: boolean = false
testAnimate: any = { state: 'inactive' }

// method
toggleState(){
    this.testAnimate.state == 'inactive' ? this.testAnimate.state = 'active' : this.testAnimate.state = 'inactive'
    this.clientTable = true
}

但是,如果我删除*ngIf,ng2-animation将工作。

理论上,ngIf检查它是否是真的。元素可以在DOM上使用。根据我的理解,元素也应该具有非活动状态,因为它不是被触发的。单击触发器后,元素将可用,并具有活动状态。

但为什么它没有任何动画?

有什么工作可以让我使用ngIf和动画吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-13 06:14:40

应该能解决这个问题,

代码语言:javascript
复制
toggleState(){

    this.clientTable = true          //<<<===changed order.

    this.testAnimate.state == 'inactive' ? this.testAnimate.state = 'active' : this.testAnimate.state = 'inactive'

}

如果它不起作用(解决办法)

代码语言:javascript
复制
toggleState(){

    this.clientTable = true          //<<<===changed order.

    setTimout(()=>{
       this.testAnimate.state == 'inactive' ? this.testAnimate.state = 'active' : this.testAnimate.state = 'inactive'
    },2000)

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40013502

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档