#1 SearchComponent now reacts to changes from outside
This commit is contained in:
parent
5952871a3e
commit
e7080a058c
@ -11,6 +11,8 @@ export class SearchComponent<T> implements OnInit {
|
|||||||
|
|
||||||
private changedTimeout: number | undefined;
|
private changedTimeout: number | undefined;
|
||||||
|
|
||||||
|
private initial_?: number;
|
||||||
|
|
||||||
@ViewChild('input')
|
@ViewChild('input')
|
||||||
input2?: ElementRef;
|
input2?: ElementRef;
|
||||||
|
|
||||||
@ -23,9 +25,6 @@ export class SearchComponent<T> implements OnInit {
|
|||||||
@Input()
|
@Input()
|
||||||
searchService!: ISearchService;
|
searchService!: ISearchService;
|
||||||
|
|
||||||
@Input()
|
|
||||||
initial?: number;
|
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
allowEmpty: boolean = true;
|
allowEmpty: boolean = true;
|
||||||
|
|
||||||
@ -42,13 +41,24 @@ export class SearchComponent<T> implements OnInit {
|
|||||||
|
|
||||||
cancelOnBlur: boolean = true;
|
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() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
if (this.initial) {
|
|
||||||
this.searchService.searchById(this.initial, result => this.selected = result, _ => _);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
changed(): void {
|
changed(): void {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user