将输入清除按钮添加到PrimeNG p下拉列表中

时间:2018-11-05 17:39:42

标签: html typescript angular5 primeng primeng-dropdowns

我正在使用PrimeNG,但无法添加一些按钮来清除输入。 这是我的html:

<p-dropdown (keyup)='search($event)'  
                        id = "dropdown"
                        (onChange)="changeSubject($event.value)" 
                        [options]="subjects" 
                        [(ngModel)]="selectedSubject" 
                        filterBy = 'subjects'
                        [filter] = 'true'
                        [autoDisplayFirst] = 'defaultFilter'
                        #dropdown
                        placeholder="{{selectedWord}}"
                        [style]="{'width':'100%', 'height': '30px'}">
            </p-dropdown>

1 个答案:

答案 0 :(得分:0)

您可以添加showClear属性,并将其设置为 true

<p-dropdown (keyup)='search($event)'  
                    id = "dropdown"
                    (onChange)="changeSubject($event.value)" 
                    [options]="subjects" 
                    [(ngModel)]="selectedSubject" 
                    filterBy = 'subjects'
                    [filter] = 'true'
                    [autoDisplayFirst] = 'defaultFilter'
                    #dropdown
                    placeholder="{{selectedWord}}"
                    [style]="{'width':'100%', 'height': '30px'}"
                    showClear="true">
        </p-dropdown>