简体   繁体   English

在ionic v2中单击按钮时切换片段

[英]Switch segments on button click in ionic v2

I'm trying to create multi page forms using segment. 我正在尝试使用细分创建多页表单。 I tried searching for examples but couldn't find any. 我尝试搜索示例,但找不到任何示例。

This is how my multi page form looks like now, 这就是我的多页表单现在的样子, 第1页

在此处输入图片说明

My question is how can I switch to next segment on button click(in my case its the next button which should make the user go to next segment). 我的问题是如何在单击按钮时切换到下一个分段(在我的情况下是下一个应使用户进入下一个分段的按钮)。 Thanks in advance! 提前致谢!

You can do something like this: 您可以执行以下操作:

    <div [ngSwitch]="Segments">
        <div *ngSwitchCase="1">
            SEGMENT CONTENT
            <button ion-button (click)="Segments = 2">NEXT</button>
        </div>
        <div *ngSwitchCase="2">
            SEGMENT CONTENT
            <button ion-button (click)="Segments = 3">NEXT</button>
        </div>
        <div *ngSwitchCase="3">
            SEGMENT CONTENT
            <button ion-button (click)="Segments = 4">NEXT</button>
        </div>
        ...
    </div>

    <ion-segment [(ngModel)]="Segments">
        <ion-segment-button value="1">
            1 >
        </ion-segment-button>
        <ion-segment-button (ionSelect)="Segments = 2" value="2">
            2 >
        </ion-segment-button>
        ...
    </ion-segment>

And then use a formBuilder for validation and getting all the data from the segment fields. 然后使用formBuilder进行验证并从segment字段获取所有数据。 Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM