@@ -4,11 +4,12 @@ import {
44  HostBinding , 
55  Input , 
66  OnDestroy , 
7-   OnInit 
7+   OnInit , 
8+   ElementRef , 
9+   Renderer2 
810}  from  '@angular/core' ; 
911
1012import  {  ProgressbarComponent  }  from  './progressbar.component' ; 
11- import  {  ProgressbarType  }  from  './progressbar-type.interface' ; 
1213import  {  isBs3  }  from  'ngx-bootstrap/utils' ; 
1314
1415// todo: number pipe 
@@ -19,7 +20,6 @@ import { isBs3 } from 'ngx-bootstrap/utils';
1920  host : { 
2021    role : 'progressbar' , 
2122    'aria-valuemin' : '0' , 
22-     '[class]' : '"progress-bar " + (type ? "progress-bar-" + type + " bg-" + type : "")' , 
2323    '[class.progress-bar-animated]' : '!isBs3 && animate' , 
2424    '[class.progress-bar-striped]' : 'striped' , 
2525    '[class.active]' : 'isBs3 && animate' , 
@@ -33,7 +33,15 @@ export class BarComponent implements OnInit, OnDestroy {
3333  max : number ; 
3434
3535  /** provide one of the four supported contextual classes: `success`, `info`, `warning`, `danger` */ 
36-   @Input ( )  type : ProgressbarType ; 
36+   @Input ( ) 
37+   get  type ( ) : string  { 
38+     return  this . _type ; 
39+   } 
40+ 
41+   set  type ( v : string )  { 
42+     this . _type  =  v ; 
43+     this . applyTypeClasses ( ) ; 
44+   } 
3745
3846  /** current value of progress bar */ 
3947  @Input ( ) 
@@ -56,6 +64,8 @@ export class BarComponent implements OnInit, OnDestroy {
5664    return  this . percent ; 
5765  } 
5866
67+   @HostBinding ( 'class.progress-bar' )  addClass  =  true ; 
68+ 
5969  get  isBs3 ( ) : boolean  { 
6070    return  isBs3 ( ) ; 
6171  } 
@@ -66,8 +76,14 @@ export class BarComponent implements OnInit, OnDestroy {
6676  progress : ProgressbarComponent ; 
6777
6878  protected  _value : number ; 
69- 
70-   constructor ( @Host ( )  progress : ProgressbarComponent )  { 
79+   protected  _type : string ; 
80+   private  _prevType : string ; 
81+ 
82+   constructor ( 
83+     private  el : ElementRef , 
84+     @Host ( )  progress : ProgressbarComponent , 
85+     private  renderer : Renderer2 
86+   )  { 
7187    this . progress  =  progress ; 
7288  } 
7389
@@ -91,4 +107,22 @@ export class BarComponent implements OnInit, OnDestroy {
91107      this . percent  -=  totalPercentage  -  100 ; 
92108    } 
93109  } 
110+ 
111+   private  applyTypeClasses ( ) : void { 
112+     if  ( this . _prevType )  { 
113+       const  barTypeClass  =  `progress-bar-${ this . _prevType }  ; 
114+       const  bgClass  =  `bg-${ this . _prevType }  ; 
115+       this . renderer . removeClass ( this . el . nativeElement ,  barTypeClass ) ; 
116+       this . renderer . removeClass ( this . el . nativeElement ,  bgClass ) ; 
117+       this . _prevType  =  null ; 
118+     } 
119+ 
120+     if  ( this . _type )  { 
121+       const  barTypeClass  =  `progress-bar-${ this . _type }  ; 
122+       const  bgClass  =  `bg-${ this . _type }  ; 
123+       this . renderer . addClass ( this . el . nativeElement ,  barTypeClass ) ; 
124+       this . renderer . addClass ( this . el . nativeElement ,  bgClass ) ; 
125+       this . _prevType  =  this . _type ; 
126+     } 
127+   } 
94128} 
0 commit comments