ionic 3 angular 4 animation not working

前端 未结 1 531
南方客
南方客 2021-01-28 11:11

I have a component where I am trying to animate an accordion list.. I have made all the changes such as including import { BrowserModule } from \"@angular/platform-browse

相关标签:
1条回答
  • 2021-01-28 12:09

    Ok after many hours of headache and failure I made a better one

    .ts

    @Component({
      selector: "page-job-details",
      templateUrl: "job-details.html",
      animations: [
        trigger('expand', [
          state('ActiveGroup', style({opacity: '1', height: '*'})),
          state('NotActiveGroup', style({opacity: '0', height: '0', overflow: 'hidden'})),
          transition('ActiveGroup <=> NotActiveGroup', animate('300ms ease-in-out'))
        ])
      ]
    })
    
    ionViewDidLoad() {
      this.items = [
        {title: 'First Button', data: 'First-content', activeGroup: 'NotActiveGroup'},
        {title: 'Second Button', data: 'Second-content', activeGroup: 'NotActiveGroup'},
        {title: 'Third Button', data: 'Third-content', activeGroup: 'NotActiveGroup'}
      ];
    }
    
    expandItem(item){
    
      this.items.map(listItem => {
        if (item == listItem){
          listItem.activeGroup = listItem.activeGroup === 'ActiveGroup' ? 'NotActiveGroup' : 'ActiveGroup';
        }
        return listItem;
      });
    }
    

    .html

    <ion-content>
      <ion-item-group *ngFor="let item of items">
        <button ion-item no-lines (tap)="expandItem(item)">
         <ion-icon item-right name="ios-arrow-down" *ngIf="item.activeGroup === 'NotActiveGroup'"></ion-icon>
         <ion-icon item-right name="ios-arrow-up" *ngIf="item.activeGroup === 'ActiveGroup'"></ion-icon>    
        {{item.title}}
       </button>
    
       <div [@expand]="item.activeGroup"> 
         <div>   
          {{item.data}}
         </div>   
       </div> 
     </ion-item-group>
    </ion-content>
    
    0 讨论(0)
提交回复
热议问题