I need your help. With the help of the following code, I am trying to do a live search: when entered in input
, my targetListOptions
array, which I use in select
, option
, changed to me. The following code doesn't give me any errors, but when I enter data, nothing happens. I am searching on the name
field which comes from the backend. I'm trying to make it a normal input
without using autocomplete
. Please tell me how to implement this search, what am I doing wrong? Thank you very much
HTML
<mat-select formControlName="targetListValue">
<input formControlName="searchTargetInput">
<mat-option *ngFor="let targetItem of targetListOptions" [value]="targetItem.id">
{{ targetItem.name }}
</mat-option>
</mat-select>
Typescript
public form: FormGroup;
public targetListOptions: ITargetData[] = [];
ngOnInit(): void {
this.form = new FormGroup({
templateListValue: new FormControl(null, [Validators.required]),
searchTargetInput: new FormControl('')
})
this.form.controls.searchTargetInput.valueChanges.subscribe(() =>
this.targetListOptions = this.targetListOptions.filter(element => element.name.includes(name)));
}