我尝试用Ionic 2构建我的应用程序,为此我使用这样的火种卡:https://devdactic.com/ionic-2-tinder-cards/ 但是在一些Android设备上(sony z4 compact,sony z5 compact和HUAWEI P8 lite)下一张卡无法加载。
包含卡的数组是this.cards
我尝试用日志显示它,它包含好的值。只有在单击显示菜单按钮后才会显示卡片。或者如果使用调用voteUp(true / false)函数滑动的按钮,它可以工作,理论上调用相同的函数但结果完全不同。
我的代码:
ts文件
addNewCards(count: number) {
this.auth.getToken().subscribe(data=>{
let url='http://my.url/api/api.php/'+data+'/repas/' + count;
let result= this.http.get(url).map(data => data.json().msg)
this.cache.loadFromObservable('repas'+count, result)
.subscribe(msgs => {
for (let val of msgs){
this.cards.push(val[0]);
}
});
});
}
模板文件:
<div swing-stack #myswing1 [stackConfig]="stackConfig" (throwoutleft)="voteUp(false)" (throwoutright)="voteUp(true)" id="card-stack">
<ion-card class="card" #mycards1 swing-card *ngFor="let c of cards">
<div *ngIf="c.photo" class=" image-recipe-position">
<div class="img-recipe" [ngStyle]="{ 'background-image': 'url(' + c.photo + ')'}">
</div>
</div>
<ion-item >
<h2>{{c.title}}</h2>
{{c.ing}}
</ion-item>
<ion-row >
<ion-col col-4 offset-1 class="center-left">
<button disabled={{buttonDisabled}} (click)="voteUp(false)" class="button-choose">
<ion-icon class="dislike" name="ios-close"></ion-icon>
</button>
</ion-col>
<ion-col class="center-right" col-4 offset-2>
<button disabled={{buttonDisabled}} (click)="voteUp(true)" class="button-choose">
<ion-icon class="like" name="ios-checkmark"></ion-icon>
</button>
</ion-col>
</ion-row>
</ion-card>
</div>