我正在尝试向我的Ionic项目添加一些Ionic幻灯片导航,并且在https://forum.ionicframework.com/t/navigation-arrows-on-slider/119081/17处找到了Ionic论坛主题,并且我尝试按照此处建议的指示进行操作。
但是,我收到一个错误Cannot read property of 'nextSlide' of undefined
很明显,我已经弄乱了TS文件中的声明,但不确定如何。论坛上的建议并不具体涉及如何将逻辑集成到TypeScript文件中。
答案 0 :(得分:0)
意识到我犯了一个简单的错误(对上述问题中未包含代码表示歉意)。我在TypeScript“ imageSlides”中通过ID引用了Ionic滑块:
I used a simple logical approach which combines current date and time. That way it is absolutely unique in any given time.
public String setUniqueID(){
DateFormat dateFormat = new SimpleDateFormat("yyddmm");
Date date = new Date();
String dt=String.valueOf(dateFormat.format(date));
Calendar cal = Calendar.getInstance();
SimpleDateFormat time = new SimpleDateFormat("HHmm");
String tm= String.valueOf(time.format(new Date()));//time in 24 hour format
String id= dt+tm;
System.out.println(id);
return id;
}
This returns a unique id.
但是随后没有在HTML中给我的滑块ID:
import { Component, ViewChild } from '@angular/core';
import { IonicPage, NavController, NavParams, Slides } from 'ionic-angular';
@IonicPage()
@Component({
selector: 'page-details',
templateUrl: 'details.html',
})
export class DetailsPage {
category: any;
data: any = {};
@ViewChild('imageSlides') slides: Slides;
constructor(
public navCtrl: NavController,
public navParams: NavParams
) { }
ionViewDidLoad() {
this.data = this.navParams.get('data');
this.category = (this.navParams.get('category'));
}
goBack(){
this.navCtrl.pop();
}
nextSlide() {
this.slides.slideNext();
}
prevSlide() {
this.slides.slidePrev();
}
}
简单的解决方法是将ID应用于离子幻灯片元素。