I am trying to assign a value dynamically to auto-complete but it is not working
HTML
<label for="centerId" class="control-label">Center</label>
<p-autoComplete formControlName="center" id="centerId" [suggestions]="iCenter" placeholder="Center (required)" (completeMethod)="searchCC($event)" [style]="{'width':'85%'}" [inputStyle]="{'width':'85%'}" field="name" dataKey="id" [dropdown]="true"></p-autoComplete>
interface
export interface ICenter{
id: string,
name: string
}
ts
(for field="name" dataKey="id" the value is the same, so id=name)
iCenter: ICenter[];
also confirmed there is a value
console.log(this.center)
searchCC(event) {
this.iCenter = this.iCenter
.filter(data => data.name.toString()
.toLowerCase()
.indexOf(event.query.toString().toLowerCase()) !== -1);
}
this.ersaForm = this._fb.group({
center: ['', Validators.required],
});
this.ersaForm.patchValue({
//also tried center:center
//also tried center: [itimData.center, itimData.center],
center: [{ 'field': this.center,'dataKey': this.center}],
phone: itimData.phone,
email: itimData.email
});
***************************************UPDATE***************************************************************** Got it working , here is how
center: {id: itimData.center, name: itimData.center },