Edit: Resolved with Jojofoulk's comment.
when using the autocomplete components of angular-material,
I'm trying to use setValue
to the input form, but its [matAutocomplete]
attribute is preventing setValue
from showing on the input.
Inspecting the reactive control reveals the value is right, and removing [matAutocomplete]
makes it work,
but with it it's just not showing up.
<mat-list-item role="listitem" *ngFor="let skill of curObj.skills;index as ind">
<div>
<mat-form-field>
<input type="text" placeholder="choose skill" aria-label="Number" matInput [formControl]="skill.control" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn" (optionSelected)="optSel($event.option.value,skill)">
<mat-option *ngFor="let option of skill.filteredOptions | async" [value]="option">
{{option.name}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</div>
</mat-list-item>
skill.control.setValue("some new value");
displayFn
is to display a certain property from an Object, are you making sure you are usingsetValue()
to set the whole object object and not just the display value? The input should have the whole object when you couple it with the autoComplete using[displayWith]
Little example: stackblitz.com/edit/angular-sjktt2 – Zoologist