Angular 2:如何在切换单选按钮时清除下拉列表和文本框值 [英] Angular 2 : how to clear the dropdown and textbox values while switching the radio buttons

查看:70
本文介绍了Angular 2:如何在切换单选按钮时清除下拉列表和文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户界面显示两个单选按钮,一个是是",一个是否",如果用户单击是"单选按钮,则我正在显示下拉菜单,如果用户单击否"然后显示文本框,现在如何在单选按钮之间切换时清除下拉列表和文本框的值,文本框和下拉菜单在切换时都会显示以前的值.请帮帮我.

UI shows two radio buttons, one is YES and one is NO, if user clicks YES radio then I am showing dropdown and if he clicks NO then showing textbox, now how to clear the dropdown and textbox values while switching between radio buttons, both textbox and dropdown showing previous values while switching.please help me.

<div id="radio" class="row">Are you an existing client?</p>

         <div class="form-check form-check-inline">
             <label class="form-check-label">
                <input type="radio" [(ngModel)]="radioValue" value="yes"/>yes
             </label>
         </div>

         <div class="form-check form-check-inline">
                <label class="form-check-label">
                <input type="radio" [(ngModel)]="radioValue" value="no"/>no
                </label>
         </div>
         </div>

      <label *ngIf="radioValue == 'yes'">Select Client</label>
             <select #select [(ngModel)]="cuurent" (change)=logDropdown(select.value) class="form-control input-group" 
                 *ngIf="radioValue == 'yes'">
                <option *ngFor="let item of list" [value]="item.id">{{item.name}}</option>
            </select>

         <div class="form-group">
            <label  *ngIf="radioValue == 'no'">Enter Client</label>  
            <input type="text" [(ngModel)]="inputsic" class="form-control input-group" *ngIf="radioValue == 'no'" />
         </div>
          </div>

推荐答案

<input type="radio" [(ngModel)]="radioValue" (ngModelChange)="reset()" value="yes"/>yes
<input type="radio" [(ngModel)]="radioValue" (ngModelChange)="reset()" value="no"/>no

reset() {
  this.inputsic = '';
  this.current = null;
}

这篇关于Angular 2:如何在切换单选按钮时清除下拉列表和文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆