1
- import { Component , EventEmitter , Input , OnDestroy , OnInit , Output } from '@angular/core' ;
1
+ import { Component , EventEmitter , Input , OnChanges , OnDestroy , OnInit , Output , SimpleChanges } from '@angular/core' ;
2
2
import { FormBuilder , FormGroup } from '@angular/forms' ;
3
3
import { distinctUntilChanged , filter , takeUntil } from 'rxjs/operators' ;
4
4
import { combineLatest , merge , Subject } from 'rxjs' ;
@@ -8,12 +8,14 @@ import { combineLatest, merge, Subject } from 'rxjs';
8
8
templateUrl : './converter.component.html' ,
9
9
styleUrls : [ './converter.component.scss' ]
10
10
} )
11
- export class ConverterComponent implements OnInit , OnDestroy {
11
+ export class ConverterComponent implements OnInit , OnDestroy , OnChanges {
12
12
13
13
@Input ( ) currencies : string [ ] ;
14
14
15
15
@Input ( ) rate : number ;
16
16
17
+ @Input ( ) activeCurrency : string ;
18
+
17
19
@Output ( ) currencyChanged = new EventEmitter < { from : string , to : string } > ( ) ;
18
20
19
21
form : FormGroup ;
@@ -57,4 +59,10 @@ export class ConverterComponent implements OnInit, OnDestroy {
57
59
this . destroy$ . complete ( ) ;
58
60
}
59
61
62
+ ngOnChanges ( changes : SimpleChanges ) : void {
63
+ if ( changes && changes . activeCurrency && changes . activeCurrency . currentValue ) {
64
+ this . form . get ( 'fromCurrency' ) . setValue ( this . activeCurrency ) ;
65
+ }
66
+ }
67
+
60
68
}
0 commit comments