PrimeNg DropDown-用户无法清除该值 [英] PrimeNg DropDown - User can't clear the value
问题描述
我正在Angular2应用程序中实现primeNg下拉组件.
I'm implementing primeNg dropdown component in my Angular2 application.
<p-dropdown [options]="listCustomers_itm" placeholder="Selezionare" [(ngModel)]="Customer_itm" [ngModelOptions]="{standalone: true}" [style]="{'width':'225px'}" filter="filter" (onChange)="onCustomerSelect($event.value)">
</p-dropdown>
除一件烦人的事情外,其他一切正常:
All works fine except one annoing thing:
一旦用户选择了一个选项,他将无法清除所选的值 ...
Once time the user has selected an option, he can't clear the selected value...
你能帮我吗?
推荐答案
要解决此问题,我必须为下拉菜单设置一个占位符.我使用的代码如下:
To fix this, I had to set a placeholder for the dropdown. The code I used is something like:
template.html
<p-dropdown ...
placeholder="Select"
#dropDownThing></p-dropdown>
<button (click)="onButtonClick()"></button>
component.ts
import { Dropdown } from "primeng/components/dropdown/dropdown";
...
@ViewChild('dropDownThing')
dropDownThing: Dropdown;
...
onButtonClick() {
this.dropDownThing.value = <someValueNotInTheDropdown'sList>;
}
...
在运行上面的代码 的情况下,当前选择的选项保持选中状态.
When the code above is run without a placeholder, the currently-selected option remains selected.
当上面的代码与占位符一起运行 时,下拉菜单的值将更改为提供的占位符.
When the code above is run with a placeholder, the dropdown's value changes to the provided placeholder.
这篇关于PrimeNg DropDown-用户无法清除该值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!