PrimeNg Angular2 Autocomplete Clear all
Asked Answered
D

3

5

Right now, I am using primeng autocomplete dropdown and in this we don't have functionality of clear/reset.

When i selecting a result from droplist, a clear/reset icon (x) should appears in input and click on (x) it will clear the inputbox.

<p-autoComplete [(ngModel)]="text" [suggestions]="results" (completeMethod)="search($event)"
            [dropdown]="true"></p-autoComplete>

Anyone have any better solution for this.

Dorwin answered 20/7, 2018 at 8:38 Comment(0)
N
6

Just add type=search <p-autocomplete type="search" ...>

Nunatak answered 31/7, 2019 at 7:52 Comment(0)
L
2
<p-autoComplete [(ngModel)]="text" [suggestions]="results" (completeMethod)="search($event)" [dropdown]="true"></p-autoComplete>
<i class="fa fa-reset" (click)="onClear()"></i>       

onClear(){
    this.text='';
}
Lightner answered 12/10, 2018 at 6:45 Comment(1)
I had to use << this.text=undefined; >>Chamaeleon
S
0

You can use PrimeNg Chip. When an option is selected from the dropdown you can display the value in a chip which as a close button on it. This is the cleanest and most visually pleasant way to do it.

Santalaceous answered 20/7, 2018 at 17:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.