|
@ -9,7 +9,7 @@ import { |
|
|
OnInit, |
|
|
OnInit, |
|
|
ViewChild |
|
|
ViewChild |
|
|
} from '@angular/core'; |
|
|
} from '@angular/core'; |
|
|
import { FormControl, NgControl } from '@angular/forms'; |
|
|
import { FormControl, FormGroupDirective, NgControl } from '@angular/forms'; |
|
|
import { |
|
|
import { |
|
|
MatAutocomplete, |
|
|
MatAutocomplete, |
|
|
MatAutocompleteSelectedEvent |
|
|
MatAutocompleteSelectedEvent |
|
@ -42,7 +42,7 @@ export class CurrencySelectorComponent |
|
|
implements OnInit, OnDestroy |
|
|
implements OnInit, OnDestroy |
|
|
{ |
|
|
{ |
|
|
@Input() private currencies: Currency[] = []; |
|
|
@Input() private currencies: Currency[] = []; |
|
|
@Input() defaultValue: Currency; |
|
|
@Input() private formControlName: string; |
|
|
|
|
|
|
|
|
@ViewChild(MatInput, { static: false }) private input: MatInput; |
|
|
@ViewChild(MatInput, { static: false }) private input: MatInput; |
|
|
|
|
|
|
|
@ -58,6 +58,7 @@ export class CurrencySelectorComponent |
|
|
public readonly _elementRef: ElementRef, |
|
|
public readonly _elementRef: ElementRef, |
|
|
public readonly _focusMonitor: FocusMonitor, |
|
|
public readonly _focusMonitor: FocusMonitor, |
|
|
public readonly changeDetectorRef: ChangeDetectorRef, |
|
|
public readonly changeDetectorRef: ChangeDetectorRef, |
|
|
|
|
|
private readonly formGroupDirective: FormGroupDirective, |
|
|
public readonly ngControl: NgControl |
|
|
public readonly ngControl: NgControl |
|
|
) { |
|
|
) { |
|
|
super(_elementRef, _focusMonitor, ngControl); |
|
|
super(_elementRef, _focusMonitor, ngControl); |
|
@ -65,17 +66,23 @@ export class CurrencySelectorComponent |
|
|
this.controlType = 'currency-autocomplete'; |
|
|
this.controlType = 'currency-autocomplete'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnChanges() { |
|
|
|
|
|
if (this.defaultValue) { |
|
|
|
|
|
this.value = this.defaultValue; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ngOnInit() { |
|
|
public ngOnInit() { |
|
|
if (this.disabled) { |
|
|
if (this.disabled) { |
|
|
this.control.disable(); |
|
|
this.control.disable(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const formGroup = this.formGroupDirective.form; |
|
|
|
|
|
|
|
|
|
|
|
if (formGroup) { |
|
|
|
|
|
const control = formGroup.get(this.formControlName); |
|
|
|
|
|
|
|
|
|
|
|
if (control) { |
|
|
|
|
|
this.value = this.currencies.find(({ value }) => { |
|
|
|
|
|
return value === control.value; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.control.valueChanges |
|
|
this.control.valueChanges |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|