Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/wizard.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Output, EventEmitter, ContentChildren, QueryList, AfterContentInit } from '@angular/core';
import { Component, Output, Input, EventEmitter, ContentChildren, QueryList, AfterContentInit, OnChanges } from '@angular/core';
import { WizardStepComponent } from './wizard-step.component';

@Component({
Expand Down Expand Up @@ -34,21 +34,30 @@ import { WizardStepComponent } from './wizard-step.component';
'.completed { cursor: default; }'
]
})
export class WizardComponent implements AfterContentInit {
export class WizardComponent implements AfterContentInit, OnChanges {
@ContentChildren(WizardStepComponent)
wizardSteps: QueryList<WizardStepComponent>;

private _steps: Array<WizardStepComponent> = [];
private _isCompleted: boolean = false;

@Input() forceStep: number;
@Output()
onStepChanged: EventEmitter<WizardStepComponent> = new EventEmitter<WizardStepComponent>();

constructor() { }

ngAfterContentInit() {
this.wizardSteps.forEach(step => this._steps.push(step));
this.steps[0].isActive = true;
if (this.steps.length) {
this.steps[0].isActive = true;
}
}

ngOnChanges() {
if (this.forceStep) {
this.revertToStep(this.forceStep);
}
}

get steps(): Array<WizardStepComponent> {
Expand Down Expand Up @@ -89,6 +98,12 @@ export class WizardComponent implements AfterContentInit {
}
}

public revertToStep(stepIndex: any) {
this._isCompleted = false;
let nextStep: WizardStepComponent = this.steps[stepIndex];
this.goToStep(nextStep);
};

public next(): void {
if (this.hasNextStep) {
let nextStep: WizardStepComponent = this.steps[this.activeStepIndex + 1];
Expand Down