angular - Ionic v4 和 Angular 无法获取循环生成幻灯片的 ion-slide 的内部文本
问题描述
我在<ion-slide>
使用*ngFor
循环定义的数组时显示了一个数组:
status: string[] = [
'Active',
'Inactive',
'Ended'
];
@ViewChild('slideWithNav') slides: IonSlides;
@ViewChild('status') slide: IonSlide;
这是html脚本:
<ion-slides class="fullWidth" [options]="slideOptsOne" #slideWithNav (ionSlideDidChange)="SlideDidChange($event)">
<ion-slide #status *ngFor="let s of status" >
<ion-col>
{{s}}
</ion-col>
</ion-slide>
</ion-slides>
当幻灯片发生变化时,我需要获取 , 的值s
来运行特定的功能。
我尝试使用以下方式访问它(ionSlideDidChange)
:
SlideDidChange(s) {
console.log(this.slides);
}
但我找不到任何与<ion-slide>
内在价值相关的东西。
我尝试了以下脚本:
import { Slides } from 'ionic-angular';
import { ViewChild, ViewChildren, QueryList } from '@angular/core';
@ViewChildren('CardSlider') cardSliders: QueryList<Slides>;
onCardChanged(){ let slides= this.slides.toArray();
let slider= slides[this.currentSuitIndex];
this.currentCardIndex[this.currentSuitIndex] = cardSlider.getActiveIndex();
console.log('Status', slider.getActiveIndex());
}
但它也没有奏效。所需的输出是当我在Active
幻灯片中时,我需要控制台“活动”并运行所需的方法。
解决方案
我找到了解决方案。显然,激活的索引是一个承诺:
SlideDidChange(s)
{
this.slides.getActiveIndex().then(
(index)=>{
this.currentIndex = index;
});
}
通过使用.then()
,我们可以获得当前索引,并使用SWITCH
案例到案例索引并相应地运行所需的方法。
推荐阅读
- firebase - 如何在 Firebase 颤振应用程序中合并两个集合?
- php - Cakephp - 在 if 中显示列表元素
- javascript - 如何检查对象数组是否所有值都重复?
- javascript - 需要在JS中更改span的文本内容只有当输入不为空时(现在,它一直在更新)
- azure - 如何通过用户 ID 而不是客户端 ID 通过 Powershell 或 Postman 访问令牌
- android - 如何根据字符串值禁用列表视图项?
- reactjs - React Navigation:实现注销导航的最佳方式?
- javascript - 如何使用带有 Tone.Player 的音频缓冲区播放音调?
- python - 使用 2 个变量进行列表理解
- wifi - 访问 ESP8266 上的原始数据包数据