I am using autocomplete component(i,e Display value autocomplete) for my project.Here is the stackblitz example
3 Answers
Use FormControl SetValue method to set Default Value
this.myControl.setValue( {name: 'Mary'}); 4 Comments
Beetlejuice
@Chellappan, how about passing different value and text ?
Chellappan வ
you mean different key value pair?
brt
The stackblitz doesn't appear to be setting a default value
Chellappan வ
@brt it is working fine in stackblitz
Use RxJs' tap operator : stackblitz
ngOnInit() { this.filteredOptions = this.myControl.valueChanges .pipe( startWith<string | User>(''), map(value => typeof value === 'string' ? value : value.name), map(name => name ? this._filter(name) : this.options.slice()), tap(() => this.myControl.setValue(this.options[0])) ); } 