简体   繁体   中英

Prev and Next buttons in Angular

I want to go from page 1 to page 4, in Angular 4, with a prev and next button. Each page, from 1 to 4, is a individual component.

My buttons component is on the bottom on each page.

<div class="d-flex flex-row">
 <div class="trade-75"><button type="button" class="btn trade-back">

 </button></div>
 <div class="trade-10"><button type="button" class="btn trade-next">

 </button></div>
</div>

I was thinking to put in an array all components and to loop thought this array, but I don't know how to do this in Angular 4 :). Is there anyone who can help me?

I would probably do something simple like this

<div class="page">
    <my-first-page *ngIf="currentPage == 0"></my-first-page>
    <my-second-page *ngIf="currentPage == 1"></my-second-page>
    <my-third-page *ngIf="currentPage == 2"></my-third-page>
    <my-fourth-page *ngIf="currentPage == 3"></my-fourth-page>
</div>
<div class="d-flex flex-row">
    <div class="trade-75">
        <button type="button" class="btn trade-back" (click)="changePage(-1)"></button>
    </div>
     <div class="trade-10">
        <button type="button" class="btn trade-next" (click)="changePage(1)"></button>
    </div>
</div>

and in a component

export class WizardComponent {
    public currentPage = 0;
    public changePage(delta: number): void {
        // some checks
        currentPage += delta;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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