Skip to content

Commit

Permalink
Add public accessor and Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
maiyaporn committed Jun 18, 2017
1 parent 7b9e17a commit 09f5d36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
10 changes: 4 additions & 6 deletions src/wizard-step.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Component, Input, Output, EventEmitter } from '@angular/core';

@Component({
selector: 'wizard-step',
Expand All @@ -9,7 +9,7 @@ import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
</div>
`
})
export class WizardStepComponent implements OnInit {
export class WizardStepComponent {
@Input() title: string;
@Input() hidden: boolean = false;
@Input() isValid: boolean = true;
Expand All @@ -25,10 +25,8 @@ export class WizardStepComponent implements OnInit {

constructor() { }

ngOnInit() {
}

@Input('isActive') set isActive(isActive: boolean) {
@Input('isActive')
set isActive(isActive: boolean) {
this._isActive = isActive;
this.isDisabled = false;
}
Expand Down
17 changes: 7 additions & 10 deletions src/wizard.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, Output, EventEmitter, ContentChildren, QueryList, AfterContentInit } from '@angular/core';
import { Component, Output, EventEmitter, ContentChildren, QueryList, AfterContentInit } from '@angular/core';
import { WizardStepComponent } from './wizard-step.component';

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

Expand All @@ -46,9 +46,6 @@ export class WizardComponent implements OnInit, AfterContentInit {

constructor() { }

ngOnInit() {
}

ngAfterContentInit() {
this.wizardSteps.forEach(step => this._steps.push(step));
this.steps[0].isActive = true;
Expand All @@ -74,7 +71,7 @@ export class WizardComponent implements OnInit, AfterContentInit {
}
}

private get activeStepIndex(): number {
public get activeStepIndex(): number {
return this.steps.indexOf(this.activeStep);
}

Expand All @@ -86,13 +83,13 @@ export class WizardComponent implements OnInit, AfterContentInit {
return this.activeStepIndex > 0;
}

goToStep(step: WizardStepComponent) {
public goToStep(step: WizardStepComponent): void {
if (!this.isCompleted) {
this.activeStep = step;
}
}

next() {
public next(): void {
if (this.hasNextStep) {
let nextStep: WizardStepComponent = this.steps[this.activeStepIndex + 1];
this.activeStep.onNext.emit();
Expand All @@ -101,7 +98,7 @@ export class WizardComponent implements OnInit, AfterContentInit {
}
}

previous() {
public previous(): void {
if (this.hasPrevStep) {
let prevStep: WizardStepComponent = this.steps[this.activeStepIndex - 1];
this.activeStep.onPrev.emit();
Expand All @@ -110,7 +107,7 @@ export class WizardComponent implements OnInit, AfterContentInit {
}
}

complete() {
public complete(): void {
this.activeStep.onComplete.emit();
this._isCompleted = true;
}
Expand Down

0 comments on commit 09f5d36

Please sign in to comment.