4

我正在尝试实现Ionic2 的 Slides,但我找不到如何设置设置:

离子幻灯片“选项”已被弃用。请改用 ion-slide 的输入属性。

我可以找到“输入属性”(例如自动播放、速度、方向),但我不知道在哪里放置它。我发现的每个示例都[options]="slideOptions"在哪里slideOptions设置,但这不会导致除弃用通知之外的任何结果。

我是 ionic v2 和 typescript 的新手,我可能会得到一个 hacky 解决方案来工作,但我想把它做好。


中的 HTML ion-content

<ion-slides [options]="slideOptions">
    <ion-slide *ngFor="let item of items">
        <img width="20%"src="{{item.thumb.source}}">
    </ion-slide>
</ion-slides>

和简化类: import { Slides } from 'ionic-angular';

@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
    }
}
4

2 回答 2

7

离子载玻片已更改。确保您已更新到最新的 ionic 版本(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>

于 2017-02-02T09:47:39.473 回答
0

输入属性意味着仅在 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是具有特定数值的组件中的变量。

于 2017-02-02T09:03:13.423 回答