我正在尝试实现Ionic2的幻灯片,但我找不到如何设置设置:
离子幻灯片"选项"已被弃用。请改用离子玻片的输入属性。
我可以找到"输入属性"(例如自动播放、速度、方向),但我不知道将其放在哪里。我找到的每个示例都[options]="slideOptions"
设置slideOptions
在哪里,但这不会导致除弃用通知之外的任何结果。
我是 ionic v2 和打字稿的新手,我可能会得到一个黑客解决方案来工作,但我想做对。
ion-content
中的 HTML :
<ion-slides [options]="slideOptions">
<ion-slide *ngFor="let item of items">
<img width="20%"src="{{item.thumb.source}}">
</ion-slide>
</ion-slides>
和简化类: 从"离子角度"导入 { 幻灯片 };
@Component({
selector: 'page-example',
templateUrl: 'example.html'
})
export class Example {
public items: any;
private slideOptions: any;
@ViewChild(Slides) slides: Slides;
constructor(private navCtrl: NavController, public navParams: NavParams) {
this.items = [];
this.albumInfo = navParams.get('item');
this.getSlides();
}
// This does nothing:
goToSlide() {
this.slides.slideTo(2, 500);
}
// This does nothing:
ngAfterViewInit() {
this.slides.autoplay = 2000;
}
// Simple example of getting the slides
makeGetRequest():Promise<string> {
/* Get the items code, populates this.items
}
}
离子载玻片已更改。确保您已更新到最新的离子版本(2.0)网站中列出的输入属性可以直接在 HTML 中使用。例如:
<ion-slides pager loop autoplay="2000">
<ion-slide> ... </ion-slide>
</ion-slides>
要使用输入属性中列出的属性以外的属性,可以在 HTML 中使用变量。
<ion-slides #slides>
...
</ion-slides>
并在 TS 中使用它:
import { Component, ViewChild } from '@angular/core';
import {Slides} from 'ionic-angular'
export class Example {
@ViewChild(Slides) slides: Slides;
constructor() {}
ngAfterViewInit() {
this.slides.autoplay = 2000;
this.slides.autoplayDisableOnInteraction = false;
}
}
在您的情况下,ngAfterViewInit 不执行任何操作,因为您没有将 html 中的变量定义为<ion-slides #slides>
输入属性意味着只有 html 中设置的属性 ion-slides
和输出事件是 html 事件。例如:
<ion-slides [autoplay]="num">
<ion-slide *ngFor="let item of items">
<img width="20%"src="{{item.thumb.source}}">
</ion-slide>
</ion-slides>
其中num
是具有特定数字值的组件中的变量。