To make default selection in autocomplete (material)

Viewed 21540

I am using autocomplete component(i,e Display value autocomplete) for my project.Here is the stackblitz example

How can i set a any one list item as default ? like this enter image description here

3 Answers

set Initial value of FormControl

myControl = new FormControl({name: 'Shelley'});

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]))
      );
  }
Related