Skip to content

Commit 650ac80

Browse files
committed
feat(ngx-material-pages): added synchronization between the page content and outlook
1 parent 9f27721 commit 650ac80

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/module/components/ngx-material-pages/ngx-material-pages.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<mat-toolbar color="primary">
66
</mat-toolbar>
77

8-
<mat-vertical-stepper>
8+
<mat-vertical-stepper [selectedIndex]="index" (selectionChange)="onStepSelectionChange($event)">
99
<mat-step *ngFor="let page of pages;let i = index;">
1010
<ng-container [ngTemplateOutlet]="page.pageOutlook.content"></ng-container>
1111
</mat-step>

src/module/components/ngx-material-pages/ngx-material-pages.component.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ViewEncapsulation
1010
} from '@angular/core';
1111
import {NgxMaterialPageLoaderComponent} from './ngx-material-page-loader/ngx-material-page-loader.component';
12+
import {StepperSelectionEvent} from '@angular/cdk/stepper';
1213

1314
@Component({
1415
selector: 'ngx-material-pages',
@@ -21,14 +22,45 @@ export class NgxMaterialPagesComponent implements OnInit, AfterContentInit {
2122

2223
@ContentChildren(NgxMaterialPageLoaderComponent) pages: QueryList<NgxMaterialPageLoaderComponent>;
2324

25+
// current page
26+
index: number;
27+
28+
// the total number of pages to render
29+
totalPages: number;
30+
2431
constructor() {
32+
this.index = 0;
2533
}
2634

2735
ngOnInit() {
2836
}
2937

3038
ngAfterContentInit() {
3139
console.log('pagesOutlook', this.pages);
40+
this.totalPages = this.pages.length;
41+
}
42+
43+
/**
44+
* Go to the previous page if it exists
45+
*/
46+
previous() {
47+
console.log('index before', this.index);
48+
this.index = this.index === 0 ? 0 : --this.index;
49+
console.log('index after', this.index);
50+
}
51+
52+
/**
53+
* Go to the next page if it exists
54+
*/
55+
next() {
56+
console.log('index before', this.index);
57+
this.index = this.index === this.totalPages - 1 ? this.totalPages - 1 : ++this.index;
58+
console.log('index after', this.index);
59+
}
60+
61+
onStepSelectionChange(event: StepperSelectionEvent) {
62+
console.log('event = ', event);
63+
this.index = event.selectedIndex;
3264
}
3365

3466
}

0 commit comments

Comments
 (0)