[英]Set default dropdown bindLabel in @ng-select/ng-select on self change event in Angular?
I have one scenario where i want to set default value to null
in ng-select . 我有一种情况,我想在ng-select中将默认值设置为
null
。 if user select dropdown first then on change event should check Amount
model is not null or blank afterward if Amount
model is blank then ng-select
should be set to null 如果用户首先选择下拉菜单,则在发生更改事件时应检查
Amount
模型不为null或之后为空,如果Amount
模型为空,则ng-select
应设置为null
In Html component 在HTML组件中
<input type="text" [(ngModel)]="Amount"/><br/><br/>
<label>Your ng-select</label><br/>
<ng-select [items]="currencyList"
bindLabel="name"
bindValue="name"
placeholder="Select Currency"
[(ngModel)]="selectedCurrency"
(change)="onChangeDropdown()">
</ng-select><br/>
In typescript on change event function 在打字稿上更改事件功能
onChangeDropdown(){
if(this.Amount){
}else{
this.selectedCurrency = null;
alert("enter amount first");
}
}
here i have attach link : link for dropdown example 在这里,我有附加链接: 下拉示例的链接
Even i also tested in normal html select dropdown this also show me as same output above 即使我也在正常的html select下拉菜单中进行了测试,这也显示出与上述相同的输出
<select [(ngModel)]="selectedCurrency" class="form-control" (change)="onChangeDropdown()">
<option>--Select Currency--</option>
<option *ngFor="let c of currencyList" value="{{c.id}}">{{c.name}}</option>
</select>
It's only working for the first time, when I select more then once it's not working. 它只是第一次工作,当我选择了更多选项之后,一旦它不工作,它就会第一次工作。 Why this showing still
INR
or other currency name on dropdown list? 为什么在下拉列表中仍显示
INR
或其他货币名称?
Change this.selectedCurrency value to undefined or empty string 将此this.selectedCurrency值更改为未定义或空字符串
onChangeDropdown(){
if(this.Amount){
}else{
this.selectedCurrency = {};
// or this.selectedCurrency = '';
alert("enter amount first");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.