oferh / ng2-completer

Angular 2 autocomplete component
http://oferh.github.io/ng2-completer/
MIT License
347 stars 172 forks source link

Unable to set initial Value #386

Open DarioN1 opened 6 years ago

DarioN1 commented 6 years ago

Hi, I have to manage a classic list of countries. The country is an information that I have to manage in a Customer Profile component...

The code I have implemented is this:

In typescript for fill the options:

this.dataServiceCountry = this.completerService.local(this.listCountry, 'nameLong', 'nameLong');

In typescript to get the id of the country:

  onCountrySelected(item: CompleterItem) {
    this.customer.idCountry = item ? item.originalObject.idCountry : null;    
  }

Then in component:

<ng2-completer id="idCountry" inputClass="form-control input-sm" [ngModelOptions]="{standalone: true}" textNoResults="Not Found"
                    [datasource]="dataServiceCountry" [minSearchLength]="0" (selected)="onCountrySelected($event)"></ng2-completer>

I can properly get the value and use it to save the record in database.

Now I want that when I load the customer profile, the ng2-completer is set to the properly value...

How to do it ? Thanks to support

zmijasu2k3 commented 5 years ago

Hi, were you able to figure this out? I am having same problem, not sure how to populate the value for existing value coming from DB.