I'm using the PrimeNG AutoComplete component in my reactive ng5 form. I've been unable to find a way to re-load the form values on page load and set the AutoComplete to a value.
The AutoComplete is mapped to an array of objects. I use the field property to tell it which field to display. What I want to pass back to my API is actually a different property. Because the AutoSelect is setting the FormControl value to the entire object I'm able to grab the property I need, although I wish there was a way to have it just set the value to the property I need. But my real problem is that I can't select a value.
I've tried:
- setValue/patchValue (setting to a POJO and a value that matches the field - neither work)
- setting a default value when I create the FormControl
This is what the HTML looks like:
<form [formGroup]="preferences">
<div class="row" style="padding-top:25px;">
<div class="col-md-12">
<div>
<h3>Station</h3>
<p>Station (or UTC) to use for time on graphical displays. Start typing for options:</p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-1">
<p-autoComplete formControlName="station" [suggestions]="filteredStations" (completeMethod)="filter($event)" field="code" [size]="30"
placeholder="Station" [minLength]="1" forceSelection="true"></p-autoComplete>
</div>
</div>
...
And the reactive form:
this.preferences = this.formBuilder.group({
station: new FormControl(),
timeDisplay: new FormControl('utc'),
itemsPerPage: new FormControl('7')
});
I've tried various ways of setting the value but nothing ends up showing up in the UI.
this.preferences.controls['station'].setValue( {
stationID: 0,
code: 'UTC',
description: 'UTC',
isActive: true,
modifiedBy: '',
modifiedOn: '',
});
There seems to be a lot of open threads on PrimeNGs forum about this and I have yet to find anything online that uses this with a reactive form. Advice would be appreciated!
TL;DR: I can't programatically populate the PrimeNG AutoComplete in my reactive form. Any examples of how to do this would be appreciated.