Add decimals precision for progress bar

This commit is contained in:
krommydas kyriakos 2017-12-07 16:00:46 +02:00
parent b8a3917522
commit 1dc50e43b9
1 changed files with 8 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service';
import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service';
import { Component, Input, OnInit } from '@angular/core';
import { FormGroup, FormControl, FormArray } from '@angular/forms'
@ -7,7 +7,8 @@ import { FormGroup, FormControl, FormArray } from '@angular/forms'
templateUrl: './progress-bar.component.html',
})
export class ProgressBarComponent implements OnInit {
@Input() formGroup: FormGroup
@Input() formGroup: FormGroup
@Input("progressValueAccuracy") public accuracy: number = 2
constructor(private visibilityRulesService: VisibilityRulesService) { }
@ -15,8 +16,11 @@ export class ProgressBarComponent implements OnInit {
ngOnInit() {
this.formGroup
.valueChanges
.subscribe(control => {
this.value = (this.countFormControlsWithValue(this.formGroup) / this.getFormControlDepthLength(this.formGroup)) * 100
.subscribe(control => {
var progressSoFar = this.countFormControlsWithValue(this.formGroup);
var total = this.getFormControlDepthLength(this.formGroup);
var perc = (progressSoFar / total) * 100;
this.value = Number.parseFloat(perc.toPrecision(this.accuracy));
})
}