#1 SearchComponent now reacts to changes from outside

This commit is contained in:
Patrick Haßel 2022-10-26 20:14:40 +02:00
parent 5952871a3e
commit e7080a058c

View File

@ -11,6 +11,8 @@ export class SearchComponent<T> implements OnInit {
private changedTimeout: number | undefined;
private initial_?: number;
@ViewChild('input')
input2?: ElementRef;
@ -23,9 +25,6 @@ export class SearchComponent<T> implements OnInit {
@Input()
searchService!: ISearchService;
@Input()
initial?: number;
@Input()
allowEmpty: boolean = true;
@ -42,13 +41,24 @@ export class SearchComponent<T> implements OnInit {
cancelOnBlur: boolean = true;
@Input()
set initial(value: number | undefined) {
this.initial_ = value;
if (this.initial) {
this.searchService.searchById(this.initial, result => this.selected = result, _ => _);
} else {
this.selected = undefined;
}
}
get initial(): number {
return this.initial_;
}
constructor() {
}
ngOnInit(): void {
if (this.initial) {
this.searchService.searchById(this.initial, result => this.selected = result, _ => _);
}
}
changed(): void {