diff --git a/src/wizard.component.ts b/src/wizard.component.ts index 8953f89a..07126888 100644 --- a/src/wizard.component.ts +++ b/src/wizard.component.ts @@ -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({ @@ -34,13 +34,14 @@ import { WizardStepComponent } from './wizard-step.component'; '.completed { cursor: default; }' ] }) -export class WizardComponent implements AfterContentInit { +export class WizardComponent implements AfterContentInit, OnChanges { @ContentChildren(WizardStepComponent) wizardSteps: QueryList; private _steps: Array = []; private _isCompleted: boolean = false; + @Input() forceStep: number; @Output() onStepChanged: EventEmitter = new EventEmitter(); @@ -48,7 +49,15 @@ export class WizardComponent implements AfterContentInit { 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 { @@ -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];