Skip to content

Commit

Permalink
fix(register service): fixed a bug that didn't allow bar unregistration
Browse files Browse the repository at this point in the history
  • Loading branch information
kKen94 committed Nov 26, 2019
1 parent 2405c6e commit 5587891
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 6 additions & 3 deletions projects/lib/src/lib/ngx-progress.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { RegisterService } from './register.service';
})
export class NgxProgressComponent implements OnInit, OnDestroy {
/**
* Color of spinner and progress bar
* Color of spinner and progress bar.
*
* Default color style attributes format ('#0984e3', 'rgb(169, 86, 90)', ...)
*/
@Input() color = '#0984e3';
Expand All @@ -22,12 +23,14 @@ export class NgxProgressComponent implements OnInit, OnDestroy {
*/
@Input() showBar = true;
/**
* Height of progress bar
* Height of progress bar.
*
* Default height style attributes format ('1px', '1%', ...)
*/
@Input() barHeight = '1px';
/**
* Width of spinner
* Width of spinner.
*
* Default width style attributes format ('5px', '5%', ...)
*/
@Input() spinnerDiameter = '10px';
Expand Down
10 changes: 9 additions & 1 deletion projects/lib/src/lib/register.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@ import { NgxProgressComponent } from './ngx-progress.component';
export class RegisterService {
private readonly existingBars: ElementRef<NgxProgressComponent>[] = [];

/**
* Registers a new bar to the existing bars array
* @param newBar: the component to register
*/
registerBar(newBar: ElementRef<NgxProgressComponent>): void {
this.existingBars.forEach(bar => {
bar.nativeElement['style']['display'] = 'none';
});
this.existingBars.push(newBar);
}

/**
* Called when a component that contains an ngx-progress is destroyed
* @param bar: the bar to unregister
*/
unregisterBar(bar: ElementRef<NgxProgressComponent>): void {
this.existingBars.splice(this.existingBars.indexOf(bar), 1);
if (this.existingBars.length) {
this.existingBars[this.existingBars.length - 1]['style']['display'] = 'inherit';
this.existingBars[this.existingBars.length - 1].nativeElement['style']['display'] = 'inherit';
}
}
}

0 comments on commit 5587891

Please sign in to comment.