很高兴我在网上搜索了很多之后终于得到了答案。不知道这个链接怎么不显示,是ionic2官方提供的。
https://forum.ionicframework.com/t/accordion-component-not-found-in-ionic-2/77576
它帮助我创建了一个符合我要求的手风琴。
这是我的带有数据列表的单个手风琴的代码:
这是我的 HTML 文件。
<ion-item color="danger" (click)="toggle()">
PopularMovies
<ion-icon item-left name="add"></ion-icon>
</ion-item>
<ion-item *ngFor="let item of popularMovieData" [@expand]="active">{{item.name}}</ion-item>
这是我的 .ts 文件
import { Component,trigger, state, style, animate, transition } from '@angular/core';
import { NavController, NavParams} from 'ionic-angular';
import { Http, Headers, RequestOptions } from '@angular/http';
@Component({
selector: 'page-search',
templateUrl: 'search.html',
styles:[
`
.item-block{
min-height: 0;
transition: 0.09s all linear;
}
`
],
animations: [
trigger('expand', [
state('true', style({ height: '45px' })),
state('false', style({ height: '0'})),
transition('void => *', animate('0s')),
transition('* <=> *', animate('250ms ease-in-out'))
])
]
})
export class Search {
popularMovieData:Array<any>=[];
active: boolean;
constructor(public navCtrl: NavController, public navParams: NavParams,public http:Http) {
this.navCtrl=navCtrl;
this.navParams=navParams;
this.active=false;
}
getPopularMovies()
{
this.http.post('enter the API url',{}).subscribe(resp=>{
this.popularMovieData = resp.data;
},
err=>{console.log(err);},
()=>{});
}
toggle()
{
this.active = !this.active
}
}