oferh / ng2-completer

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

How to set initialValue but allow user to choose sth else #378

Open jakub-wisniowski opened 6 years ago

jakub-wisniowski commented 6 years ago

I have an array of strings called mins filled with values like "00","05","10"..."55". I'm creating dataService for my completer like this:

this.dataServiceMin = completerService.local(mins, 'value','value');

and then declare the completer in the following way: <ng2-completer [(ngModel)]="min_end" name="min_end" [placeholder]="placeholder_min" [datasource]="dataServiceMinEnd" [minSearchLength]="0" [openOnClick]=true></ng2-completer>

I've tried using [initialValue]="30" or [initialValue]=mins[6] but then only option appearing in dropdown is 30. I want to set the initialValue to 30 but give user the possibility to choose another value. Is it possible?

CraigEge commented 6 years ago

Set your min_end value in the typescript file and not the HTML to set a default value.

DarioN1 commented 6 years ago

@CraigEge , I have the same problem, how can I set the initial in typescript code ?